# Apply a function to a list (map)

Apply a function to every element of a list.

## How to write it

### map(f, list)

**f**

The function to apply. Takes a function.

**list**

The elements to apply it to. Takes a list.

## Examples

- $\displaystyle \operatorname{map}(x \mapsto x^{2}, \left[ 1, 2, 3 \right]) = \left[ 1, 4, 9 \right]$

  `map(x => x^2, [1, 2, 3])`

  In the solver, `map(x => x^2, [1, 2, 3])` gives `[1, 4, 9]`.

  [Open in the solver](https://hilberon.com/?q=map%28x%20%3D%3E%20x%5E2%2C%20%5B1%2C%202%2C%203%5D%29)

## Related functions

- [map_thread](https://hilberon.com/library/map_thread)

  Apply a function to corresponding elements of several lists.
- [list](https://hilberon.com/library/list)

  A list of the arguments.
- [most](https://hilberon.com/library/most)

  A list without its last element.
- [length](https://hilberon.com/library/length)

  Number of elements in a list.
- [nest](https://hilberon.com/library/nest)

  Apply a function again and again to a value.
- [last](https://hilberon.com/library/last)

  The last element of a list.

---
Source: https://hilberon.com/library/map
