0Pricing
Swift Academy · Lesson

map and flatMap on Result

Chaining transformations on success values without nested switch statements.

Welcome

`map` and `flatMap` on `Result` let you transform success values without nested switch statements, keeping your code flat and readable.

map on Result

```swift let r: Result = .success(5) let doubled = r.map { $0 * 2 } // .success(10) let failed: Result = .failure(MyError.bad) let same = failed.map { $0 * 2 } // .failure(MyError.bad) ```

All lessons in this course

  1. Result Fundamentals
  2. map and flatMap on Result
  3. Custom Error Types with LocalizedError
  4. Bridging Result to async/await
← Back to Swift Academy