foldRight method

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

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

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

Implementation

R foldRight(R Function(R left, S seperator, R right) callback) {
  var result = elements.last;
  for (var i = elements.length - 2; i >= 0; i--) {
    result = callback(elements[i], separators[i], result);
  }
  return result;
}