Skip to main content

Iterator: Reduce

Fold a list into a single value. The sub-graph runs once per element with el, index, and the running accumulator acc exposed by the auto-created Iterator::Entry. Each iteration's new accumulator is read from the auto-created Iterator::Collect.

Mirrors JavaScript's Array.prototype.reduce.

Example
Input array: [1, 2, 3, 4]
Initial value: 0
Body: acc + el
Output: 10

Parameters

This function has no parameters.

Input

Arrayrequired

List to fold over (Array or JSON array).

Initial

Optional starting value for the accumulator. When left unwired, the first array element seeds the accumulator and iteration starts at the second element (like JavaScript's reduce without an initial value); in that case an empty array fails with a MissingConnector error.

Output

Result

The final accumulator value after all iterations.