Skip to content
Justice Tech School

Sequences

Sequences are lazy. They process items one at a time, good for big or infinite data.

Example
val s = generateSequence(1) { it * 2 }
println(s.take(6).toList())
println((1..1_000_000).asSequence().filter { it % 3 == 0 }.map { it * 2 }.first())

Exercise

Lazy collection.

list.as()

Quiz Test

Why use sequences?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.