- All Implemented Interfaces:
- Function
public class ReduceFunction
extends FunctionBase
implements Function
From http://docs.jsonata.org/higher-order-functions#reduce
Signature: $reduce(array, function [, init])
Returns an aggregated value derived from applying the function parameter successively to each value in array in combination with the result of the previous application of the function.
The function must accept at least two arguments, and behaves like an infix operator between each value within the array. The signature of this supplied function must be of the form:
myfunc($accumulator, $value[, $index[, $array]])
Example
(
$product := function($i, $j){$i * $j};
$reduce([1..5], $product)
)
This multiplies all the values together in the array [1..5] to return 120.
If the optional init parameter is supplied, then that value is used as the initial value in the aggregation (fold) process. If not supplied, the initial value is the first value in the array parameter.