16 Map

The two most famous higher order functions are map and reduce

"[Google's MapReduce] abstraction is inspired by the map and reduce primitives present in Lisp and many other functional languages"

  • Dean and Ghemawat, 2008

Let's get started with map. Map applies a function to every item in a list, and replaces with the return value.

For example:

We can double each of the natural numbers in our list with a map

Wait! This code has bad style! We don't need that anonymous function:

That's much better :)