Map
Calls a function on each element of an array and collects the results.
Node id array/map
The Map node calls function once for every element of array and outputs
the results, in the same order: one result per element. It is how a graph
does something "for each" element, such as placing a shape at every point
of a grid.
The function is a subgraph. To make one that fits,
drag a wire from Map's
function input onto empty canvas and choose
New function…, or right-click Map and choose New function….Inputs
| Name | Type | Default | Notes |
|---|---|---|---|
| array | Array<T> | — | generic |
| function | Function(T, number, ...) -> (U) | — | generic |
| arguments | X | — | multigenericindependent |
Outputs
| Name | Type | Notes |
|---|---|---|
| array | Array<U> | generic |
Behaviour
- The function has the type
Function(T, number, ...) -> (U): it gets the element and its index, and gives one value. The output is an array of those values (Array<U>). See Functions. - Extra arguments. Values connected to
arguments(a multi input) are passed to every call after the element and index, in slot order. This is how the function gets values from outside it, such as a size or a color. Each slot may have its own type. - Each call is separate. Random nodes inside the function draw new numbers on every call, so each element gets its own.
- An empty array gives an empty array, without calling the function.
Errors
functionmust be connected.- The function must take exactly as many extra parameters as there are
arguments, each of the right type. This is checked before any call, even for an empty array. - If the function fails for any element, Map fails.