foldLeftWithIndex<B> method

B foldLeftWithIndex<B>(
  1. B initialValue,
  2. B combine(
    1. B previousValue,
    2. T element,
    3. int index
    )
)

Same as foldLeft (fold) but provides also the index of each mapped element in the combine function.

Implementation

B foldLeftWithIndex<B>(
  B initialValue,
  B Function(B previousValue, T element, int index) combine,
) {
  var index = 0;
  var value = initialValue;
  for (var element in this) {
    value = combine(value, element, index);
    index += 1;
  }
  return value;
}