foldLeftWithIndex<B> method

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

Fold a List into a single value by aggregating each element of the list from the first to the last using their index.

Implementation

B foldLeftWithIndex<B>(
        B initialValue, B Function(B accumulator, T element, int index) f) =>
    fold<Tuple2<B, int>>(
      Tuple2(initialValue, 0),
      (p, e) => Tuple2(f(p.first, e, p.second), p.second + 1),
    ).first;