Understanding Kotlin’s yield function
You can think of yield() as “return, and next time start from where you stopped“: val sequence = sequence { val start = 0 yield(start) // first return yieldAll(1..5 step 2) // if called again, will start from here yieldAll(generateSequence(8) { it * 3 }) // if called more that six times, start from here … Read more