Skip to content

Esta página también está en español.

Léela en español

このページは日本語でも読めます。

日本語で読む

本页也有简体中文版本。

阅读简体中文版本

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

  • map⁡(x↦x2,[1,2,3])=[1,4,9]\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
  • map_thread

    Apply a function to corresponding elements of several lists.

  • list

    A list of the arguments.

  • most

    A list without its last element.

  • length

    Number of elements in a list.

  • nest

    Apply a function again and again to a value.

  • last

    The last element of a list.