mapMap<K1, V1, K2, V2> function

  1. @Deprecated('Use Map.map or a for loop in a Map literal.')
Map<K2, V2> mapMap<K1, V1, K2, V2>(
  1. Map<K1, V1> map,
  2. {K2 key(
    1. K1,
    2. V1
    )?,
  3. V2 value(
    1. K1,
    2. V1
    )?}
)

Creates a new map from map with new keys and values.

The return values of key are used as the keys and the return values of value are used as the values for the new map.

Implementation

@Deprecated('Use Map.map or a for loop in a Map literal.')
Map<K2, V2> mapMap<K1, V1, K2, V2>(Map<K1, V1> map,
    {K2 Function(K1, V1)? key, V2 Function(K1, V1)? value}) {
  var keyFn = key ?? (mapKey, _) => mapKey as K2;
  var valueFn = value ?? (_, mapValue) => mapValue as V2;

  var result = <K2, V2>{};
  map.forEach((mapKey, mapValue) {
    result[keyFn(mapKey, mapValue)] = valueFn(mapKey, mapValue);
  });
  return result;
}