foldLeft method

R foldLeft(
  1. R callback(
    1. R left,
    2. S seperator,
    3. R right
    )
)

Combines the elements by grouping the elements from the left and calling callback on all consecutive elements with the corresponding separator.

For example, if the elements are numbers and the separators are subtraction operations sequential values 1 - 2 - 3 are grouped like (1 - 2) - 3.

Implementation

R foldLeft(R Function(R left, S seperator, R right) callback) {
  var result = elements.first;
  for (var i = 1; i < elements.length; i++) {
    result = callback(result, separators[i - 1], elements[i]);
  }
  return result;
}