foldRightWithIndex<B> method

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

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

Implementation

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