mapIndexed<E> method

Iterable<E> mapIndexed<E>(
  1. E f(
    1. int index,
    2. T item
    )
)

Returns a new lazy Iterable with elements that are created by calling f on each element of this Iterable in iteration order.

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function f will not be invoked. The transformed elements will not be cached. Iterating multiple times over the returned Iterable will invoke the supplied function f multiple times on the same element.

Implementation

Iterable<E> mapIndexed<E>(E Function(int index, T item) f) sync* {
  var index = 0;
  for (final item in this) {
    yield f(index++, item);
  }
}