#reduce
Accumulates a single value by applying a two-parameter lambda to each element, with an optional seed.
#reduce(array, @acc;@current: expression, seed?)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
array |
path | array |
The source array. |
accumulator |
lambda |
Receives the accumulated value and the current element; returns the new accumulated value. |
seed (optional) |
any |
The starting value. |
Returns
Section titled “Returns”any — The final accumulated value, or the seed when the array is empty.
Examples
Section titled “Examples”Sum with a seed
Section titled “Sum with a seed”{ "numbers": [ 1, 2, 3 ]}{ "result": "#reduce($.numbers, @acc;@current: @acc + @current, 0)"}{ "result": 6}