Skip to main content

Vector.fold

foldinitfunction

Documentation

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

In general, the result of [l0, l1, ..., ln] . 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 a vector.

      [0, 1, 2] . fold 0 (+)