Array.fold_with_index
fold_with_indexinitfunction
Documentation
Combines all the elements of the array, by iteratively applying the passed function with next elements of the array.
Arguments
init
: The initial value for the fold.function
: A function taking the current value, an index and an item and combining them.
Examples
Compute the sum of all of the elements and indexes in an array.
[0, 1, 2].to_array . fold_with_index 0 (s->i->e->s+i+e)