Ok Ok, first of all , What are collections in Swift? It’s simple!
As mentioned in swift.org :
Swift provides three primary collection types (arrays, sets, and dictionaries) for storing collections of values.
- Arrays are ordered collections of values.
- Sets are unordered collections of unique values.
- Dictionaries are unordered collections of key-value associations.
… note that these collection types are implemented as generic types.
Assuming that you’re familiar with at least one of these types, let’s get familiar with the hero, Higher Order functions !
Higher Order functions
They’re really simple ! Higher order functions are ones that deal with other functions, either as a parameter or as a return type .
As far as we need them for this series is that there are some higher order functions built by swift for collection types such as .map, .compactMap, .flatMap, .split , .filter, .reduce, .forEach and .sort.
We’d also try to see what our world would be without these lovely functions by example while learning how to make our life easier with them .
Believe me, they’d make your coding life much easier - swiftier :)
Learn about .map, .compactMap and .flatMap in the next exciting episode =)
Next: Part (II) : What are .map , .compactMap and .flatMap in Swift?