Why Sequences
Lazy evaluation.
What Are Sequences?
A Sequence is like a collection but processes elements lazily. Operations are not run until a terminal operation requests results, and elements flow through the whole chain one at a time.
Eager Collections
Standard collection operations are eager: each step (filter, map) fully processes the list and creates a new intermediate list before the next step begins.
fun main() {
val result = listOf(1, 2, 3, 4)
.map { it * 2 }
.filter { it > 4 }
println(result)
}