Skip to main content

Vector.fold_with_index

fold_with_indexinitfunction

Documentation

Combines all the elements of the vector, by iteratively applying the passed function with next elements of the vector.

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 a vector.

      [0, 1, 2] . fold_with_index 0 (s->i->e->s+i+e)