Kotlin Sequence


#1

Started learning kotlin. I had a question. Under the hood what data structures or processes are used for Kotlin sequence so that it avoids creating intermediary temporary objects. Any explanation or links would be helpful. Thank you


#2

It uses a decorator pattern on the iterator. You can view all the decorators for each operation (filter -> FilteringSequence, map -> TransformingSequence, etc) here: https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/collections/Sequences.kt