mapIndexedSC<U> method

  1. @Deprecated('Dart natively supports this function. Read DartDoc comment for more info.')
Iterable<U> mapIndexedSC<U>(
  1. U transformer(
    1. T currentValue,
    2. int index
    )
)

Deprecation hint: Read the migration guide for more details on migrating.

Applies the function funcIndexValue to each element of this collection in iteration order. The function receives the element index as first parameter index and the element as the second parameter.

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

@Deprecated(
    'Dart natively supports this function. Read DartDoc comment for more info.')
Iterable<U> mapIndexedSC<U>(
  U Function(T currentValue, int index) transformer,
) sync* {
  final it = iterator;
  var index = 0;
  while (it.moveNext()) {
    yield transformer(it.current, index++);
  }
}