Lazy vs Eager Trade-offs
Know when laziness helps or hurts.
No Free Lunch
Lazy is not always faster. It trades upfront allocation for per-access overhead and changes when side effects run. Knowing the trade-offs lets you pick correctly.
Lazy Wins: Partial Consumption
Only a slice of a huge transform is needed — lazy skips the rest:
let data = Array(1...1_000_000)
let top = data.lazy.map { $0 * 2 }.prefix(3)
print(Array(top)) // [2, 4, 6] -- 999,997 transforms skippedAll lessons in this course
- The lazy Property
- Lazy map and filter
- Lazy vs Eager Trade-offs
- Building Custom Lazy Sequences