Skip to main content

Array.running_fold

running_foldinitfunction

Documentation

Combines all the elements of the array, by iteratively applying the passed function with the next element of the array. After each step the value is stored resulting in a new array of the same size as self.

Arguments

  • init: The initial value for the fold.
  • function: A function taking two elements and combining them.

Examples

Compute the running sum of all of the elements in an array

     [1, 2, 3].to_array.running_fold 0 (+)