4 ms·
> Kotlin's sequence pre-dates co-routines. You misunderstood. The `Sequence` type does predate coroutines. But I meant the `sequence` builder function, which t
by ackfoobar 3y ago
> Kotlin's sequence pre-dates co-routines.
You misunderstood. The `Sequence` type does predate coroutines. But I meant the `sequence` builder function, which takes a block of suspending code to create a `Sequence`.
The in-order traversal in the article can be translated to Kotlin:
fun walk(t: Tree?): Sequence<Int> = sequence {
if (t != null) {
yieldAll(walk(t.left))
yield(t.value)
yieldAll(walk(t.right))
}
}
As I have noted above, this is a use of coroutines that has nothing to do with concurrency.
- jillesvangurp 3y agoSequences actually were part of Kotlin 1.0. Co-routines were added later.
- ackfoobar 3y ago> Sequences actually were part of Kotlin 1.0. But the `sequence` builder function was not. In fact it depends on coroutines. Could you read my reply before repeating?