mapIndexed<U> method

Iterable<U> mapIndexed<U>(
  1. U transformer(
    1. T currentValue,
    2. int index
    )
)

Just like map, but with access to the element's current index.

Example

[1, 2, 3].mapIndexed((number, index) => number * 2); // [2, 4, 6]

Implementation

Iterable<U> mapIndexed<U>(
    U Function(T currentValue, int index) transformer) sync* {
  final it = iterator;
  var index = 0;
  while (it.moveNext()) {
    yield transformer(it.current, index++);
  }
}