The map() function loops over every item in a collection, and applies an operation to each element in the collection. It returns a collection of resulting items, to which the operation was applied.
The map() method of optionals allows you to transform the optional if it has a value, or do nothing if it is empty. This makes for shorter and more expressive code than doing a regular unwrap, and doesn’t require you to change your data type.
You could use the map() method to transform it safely, without having to check and unwrap it – if it were nil, the map() call would do nothing.
Here is my own Swift map() Function Implementation, that can be used with both Collection Type and Optional.
In this project I used extensions for Collection Type and Optional Type for creating myMap() function in there, which is my own implementation of "official" map() function. myMap() is declared as Generic.
You can see some examples in my code if something remains unclear to you.