Reduction
Syntax
$set.reduce($identity, $fun)
Description
Reduces the set
to a single value by applying an associative combinator function fun
.
The expression list(v1, v2, ...., vn).reduce(i, fun)
corresponds to the evaluation of fun(.... fun(fun(i, v1), v2)....), vn)
. fun
is first applied to the elements i
and v1
. Then fun
is applied to the result of these and to v2
and so on until all elements of the set have been combined.
Parameter
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
set | Set | A set of elements to be reduced to a single one. | yes | |
identity | Number/string/boolean/business object | The neutral element with respect to the combinator function fun , which means that fun(identity, x) is equal to x for each x . |
yes |
Return value
Type: Number/string/boolean/business object
The reduced element of set
.
Examples
{
list = list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$list.reduce(0, subresult -> element -> $subresult + $element)
}
Output: 55
Adds all the numbers in the set together.