map
Usage
map(f: a ->
b, xs: m<a>) → m<b>
Arguments
-
f: -
Function that takes an element and returns its replacement
-
xs: -
List or other supported container whose elements are transformed
Description
Apply f to each element of xs, preserving the container's structure. For a list, the result has the same length and element order.
In the type signature, a is the input element type, b is the output element type, and m is the container type. The function may change the element type.
In the example below, |x: x+1| defines a function that adds 1 to its argument.
Examples
map(|x: x+1|, [1,2,3]) // returns [2,3,4]