Map is a very common higher-order function.
Map takes a function and a list. It applies the function to each element in the list and returns a new list containing the outputs.
Here’s a simple example in Python (try it!):
def double(x):
return x * 2
list = [2, 3, 4, 5]
doubles = map(double, list)
print doubles
The printed output is [4, 6, 8, 10]
.
Map is often used in declarative code where a loop might be used in imperative code. When you get used to map, there are lots of situations where it can make your code a little bit simpler than it would’ve been with a loop.