0Pricing
Swift Academy · Lesson

Higher-Order Functions: map, flatMap, compactMap

Transforming sequences without mutation using Swift's collection functions.

Welcome

Higher-order functions take or return other functions. Swift's collection library is built on them: `map`, `flatMap`, `compactMap`, `filter`, `reduce`.

map — Transform Each Element

```swift let nums = [1,2,3,4] let squared = nums.map { $0 * $0 } // [1,4,9,16] let strs = nums.map(String.init) // ["1","2","3","4"] ```

All lessons in this course

  1. Pure Functions and Side-Effect-Free Design
  2. Higher-Order Functions: map, flatMap, compactMap
  3. Function Composition and Pipelines
  4. Lazy Sequences for Efficiency
← Back to Swift Academy