I wanted to take some time to talk about the humble map
function. If you have ever used libraries like underscore, lodash, or ramda, you are sure to encounter more than a few curious functions. The unassuming map
function is a good starting point on our journey to functional nirvana.
Taking a step back, what is map
? Just like normal maps (the paper kind!), map
is a guide to get from one place to another.
For example, in your notebook you have a list of numbers: 1 2 3
. Next to that list you write 2 3 4
. How did this happen? Simply enough, we went over each number in the list and added one to it. In other words, we mapped over the list of numbers and added one to them.