0Pricing
Swift Academy · Lesson

Generic algorithms on collections

Use generic algorithms like map , filter , and reduce , and write your own functions over Sequence with simple constraints.

Why generic algorithms?

Swift provides powerful, generic algorithms on Sequence/Collection: map, filter, and reduce. You can also write your own generic helpers.

map

map applies a transform to every element, returning a new array.

let nums = [1, 2, 3]
let doubled = nums.map { $0 * 2 }   // [2, 4, 6]
print(doubled)

let words = ["swift", "kit"]
let caps = words.map { $0.uppercased() } // ["SWIFT","KIT"]
print(caps)

All lessons in this course

  1. Generic functions & types
  2. Constraints (where), type inference
  3. Generic algorithms on collections
← Back to Swift Academy