Creating Sequences
From collections and generators.
Creating Sequences
There are several ways to create a Sequence: from existing collections, from elements, with a generator function, or with a builder. This lesson covers each.
From a Collection with asSequence
The most common approach is to call asSequence() on an existing collection to process it lazily.
fun main() {
val seq = listOf(1, 2, 3, 4).asSequence()
val result = seq.map { it * 2 }.toList()
println(result)
}All lessons in this course
- Why Sequences
- Creating Sequences
- Lazy Operations
- Sequences vs Collections