Take the following single-line layer, which can be expressed as a series of operations on a set or sequence:
val nums = (10 downTo 1) // .asSequence() if we want this to be a sequence .filter { it % 2 == 0 } .map { it * it } .sorted() // .asList() if declaring it a sequence println(nums) // [4, 16, 36, 64, 100]
Let's say I want to see elements at every step, they will be (from subtraction):
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1] [10, 8, 6, 4, 2] [100, 64, 36, 16, 4] [4, 16, 36, 64, 100]
Unfortunately, there is no good way to debug this using the debugger or to log these values ββfor later verification. With good functional programming constructs, whole methods can be rewritten as single statements like this, but there seems to be no good way to check intermediate states, even count ( 10, 5, 5, 5
here).
What is the best way to debug them?