0Pricing
Swift Academy · Lesson

Map, Filter and Reduce on Arrays

Transforming arrays with functional higher-order functions.

Welcome

Swift's higher-order functions — `map`, `filter`, and `reduce` — transform collections without mutation. They make your intentions explicit and eliminate error-prone loops.

map — Transform Every Element

```swift let nums = [1, 2, 3, 4] let doubled = nums.map { $0 * 2 } // [2,4,6,8] let strings = nums.map { "Item \($0)" } // ["Item 1","Item 2",...] ``` `map` applies a closure to each element and returns a new array of the results.

All lessons in this course

  1. Creating and Mutating Arrays
  2. Sorting, Searching and Slicing
  3. Map, Filter and Reduce on Arrays
  4. 2D Arrays and Nested Collections
← Back to Swift Academy