The code below is expected to display the numbers from 1 to 10, but it does not. Why?
val seq = sequence { yieldAll(1..20) }
.filter { it < 11 }
println(seq)
val seq = sequence { yieldAll(1..20) }
.filter { it < 11 }
println(seq)A. You cannot assign a sequence to a variable
B. To produce result, a sequence must have terminal operation. In this case, it needs a .toList()
C. The .filter{ it < 11 } should be .filter{ it > 11 }
D. The yieldAll(1..20) should be yieldAll(1..10)
Answer: Option B

Join The Discussion