List.reduce
reduce($callbackFunction, $startValue=none) -> any
Description
Reduce the List to a single value, by applying a callback function to each item.
The callback receives 2 arguments:
carry: the current aggregate value, returned from each iterationitem: the value of the current iteration
Returns the a single final value.
If $startValue is given, the function will use this as the starting carry value.
$fnSum = fun ($total, $i) {
return $total + $i
}
[3, 6, 9, 12].reduce($fnSum)
//= 30
[3, 6, 9, 12].reduce($fnSum, 100)
//= 130