0Pricing
Swift Academy · Lesson

The lazy Property

Defer transformation work until needed.

Eager by Default

Standard collection methods are eager: map, filter, etc. run immediately and build a full new array right away, even if you only read the first element.

Eager Work Happens Now

This builds the entire transformed array up front:

let nums = [1, 2, 3, 4, 5]
let doubled = nums.map { $0 * 2 }  // whole array built now
print(doubled.first!)  // 2

All lessons in this course

  1. The lazy Property
  2. Lazy map and filter
  3. Lazy vs Eager Trade-offs
  4. Building Custom Lazy Sequences
← Back to Swift Academy