Sequences
In Chapter 10 and Chapter 11, you were introduced to the collection types List, Set, and Map. These collection types are all known as eager collections. When an instance of any of these types is created, all the values it contains are added to the collection and can be accessed.
There is another flavor of collection: lazy collections. You learned about lazy initialization, in which a variable is not initialized until it is first accessed, in Chapter 13. Lazy collection types, similar to lazy initialization of other types, provide better performance – specifically when working with very large collections – because their values are produced only as needed.
Kotlin offers a built-in lazy collection type called Sequence
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access