fold<R> method

R fold<R>(
  1. R initial,
  2. R operation(
    1. R acc,
    2. T
    )
)

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Implementation

R fold<R>(R initial, R Function(R acc, T) operation) {
  var accumulator = initial;
  for (final element in iter) {
    accumulator = operation(accumulator, element);
  }
  return accumulator;
}