Version: v0.8.1 - Beta.  We welcome contributors & feedback.

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:

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

See Also