Swift’s god like functions: map, filter, reduce, flatmap.

Map

Map use to iterate over a collection and returns an array containing the results of mapping the given closure over the sequence’s elements.

example of map

Filter

Another palatable method use to iterate over collection and returns the array containing only those elements that match the condition.

example of filter

Reduce

This returns a single value resulted by combining all values from collection.

example of reduce

Flatmap

In simple words flatmap flattens the collection of collection.

example of flatmap

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store