eachWithIndex<T> function

void eachWithIndex<T>(
  1. List<T> list,
  2. void fn(
    1. T,
    2. int
    )
)

Call fn first with list[0] and 0, then with list[1] and 1, etc.

Implementation

void eachWithIndex<T>(List<T> list, void Function(T, int) fn) {
  int i = 0;
  for (final x in list) {
    fn(x, i);
    i += 1;
  }
}