Array.fold
foldinitfunction
Documentation
Combines all the elements of the array, by iteratively applying the passed function with next elements of the array.
In general, the result of [l0, l1, ..., ln].to_array . fold init f is the same as f (...(f (f init l0) l1)...) ln
Arguments
init
: The initial value for the fold.function
: A function taking two elements and combining them.
Examples
Compute the sum of all of the elements in an array.
[0, 1, 2].to_array . fold 0 (+)