mapWithIndex<E> method
Maps each element of the iterable along with its index using the provided
function f.
Example usage:
void main() {
const List<String> fruits = ['Apple', 'Banana', 'Orange', 'Mango'];
final indexedFruits = fruits.mapWithIndex((index, fruit) => '$index: $fruit').toList();
indexedFruits.forEach(print);
}
Implementation
Iterable<E> mapWithIndex<E>(E Function(int index, T value) f) =>
Iterable.generate(length).map((i) => f(i, elementAt(i)));