The map Function

Understand the higher-order map function and see its applications on lists, trees, options, abstract domains, and contexts.

The map function is one of the most popular abstractions in the functional programming paradigm. It is best known for mapping the elements of a list to new elements. Due to its usefulness, map has found its way into most mainstream programming languages, such as JavaScript, Java, and Python.

The map function on lists

One way of looking at map on lists is that it represents a general method of computation on lists. First, let’s write a square_list function that squares all elements in a list to see what that pattern is.

Get hands-on with 1200+ tech skills courses.