reduceRight function

dynamic reduceRight(
  1. List list,
  2. dynamic fn(
    1. dynamic prev,
    2. dynamic curr,
    3. int index,
    4. List list,
    ), [
  3. dynamic initialValue
])

Implementation

dynamic reduceRight(List list, dynamic Function(dynamic prev, dynamic curr, int index, List list) fn, [initialValue]) {
  var length = list.length;
  var index = length - 1;
  var value;
  var isValueSet = false;
  if (1 < list.length) {
    value = initialValue;
    isValueSet = true;
  }
  for (; -1 < index; --index) {
    if (isValueSet) {
      value = fn(value, list[index], index, list);
    } else {
      value = list[index];
      isValueSet = true;
    }
  }
  if (!isValueSet) {
    throw TypeError(); //'Reduce of empty array with no initial value'
  }
  return value;
}