Chapter 10. Understanding map, flatMap, and compactMap
This chapter covers
- Mapping over arrays, dictionaries, and other collections
- When and how to map over optionals
- How and why to flatMap over collections
- Using flatMap on optionals
- Chaining and short-circuiting computations
- How to mix map and flatMap for advanced transformations
Modern languages like Swift borrow many concepts from the functional programming world, and map and flatMap are powerful examples of that. Sooner or later in your Swift career, you’ll run into (or write) code that applies map and flatMap operations on arrays, dictionaries, and even optionals. With map and flatMap, you can write hard-hitting, succinct code that is immutable—and therefore safer. Moreover, since ...
Get Swift in Depth now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.