0Pricing
Kotlin Academy · Lesson

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)
}

All lessons in this course

  1. Why Sequences
  2. Creating Sequences
  3. Lazy Operations
  4. Sequences vs Collections
← Back to Kotlin Academy