fun main() {
var numbers = emptySequence<Int>()
numbers = sequence {
yieldAll(numbers)
yield(1)
}
println(numbers.iterator().next()) // throws StackOverflowError
}
I do realize that such an approach to build up a sequence may seem unnatural, but for my case (I have to implement Kotlin Serialization’s Encoder interface which methods adds/yields next value for the sequence) I haven’t figured out an alternative.
e
ephemient
07/14/2022, 9:58 PM
the
emptySequence<Int>()
part is irrelevant, you have written something (mostly) equivalent to