Skip to content

#reduce

Accumulates a single value by applying a two-parameter lambda to each element, with an optional seed.

#reduce(array, @acc;@current: expression, seed?)
Category Arrays and sequencesValid in Property value
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.

any — The final accumulated value, or the seed when the array is empty.

source.json
{
"numbers": [ 1, 2, 3 ]
}
transformer.json
{
"result": "#reduce($.numbers, @acc;@current: @acc + @current, 0)"
}
output.json
{
"result": 6
}

Try it in the playground →

#sum · #zip