mapWithIndex<A> method

Map<K, A> mapWithIndex<A>(
  1. A update(
    1. V value,
    2. int index
    )
)

Convert each value of the Map using the update function and returns a new Map.

Implementation

Map<K, A> mapWithIndex<A>(A Function(V value, int index) update) {
  final entries = this.entries;
  final mapped = <K, A>{};
  var i = 0;
  for (final item in entries) {
    mapped.addEntries([MapEntry(item.key, update(item.value, i))]);
    i += 1;
  }
  return mapped;
}