Map, CompactMap, FlatMap
3 min readJun 8, 2022
Comparing these functions
1. Map
Using a transformation closure, we may transform arrays (and indeed any kind of collection) with the map() method. Your changed items will be contained in an array of the same size as the return value.
- Convert digits of array to square of digit of array
let digits = [1,2,3,4]
let squares = digits.map {$0 *…