Higher order functions in Swift: Filter, Map, Reduce, flatmap, compactMap

Ever since I learned about functions and closures in detail, I wanted to know more about the advantages and usages of these in programming. I read about higher order functions that can be used on collection types and this is what I understood.

Abhimuralidharan
11 min readJul 22, 2017
I don’t know who that is over there at the top.

As far as I understood, higher order functions are functions that takes another function/closure as argument and returns it.

I will try to explain this first. Consider the following code which will give you an idea what a higher order function is :

Pass function to another function:

higher order functions in swift

The first two methods are of type (Double,Double)->Double . First one accepts two double values and return their sum . The second one returns the product of these two double values. The third method is a higher order function which accepts three parameters. Two double values and a function of type (Double,Double)->Double . Do have a look at the method call. You will understand…

--

--