mapMap<K1, V1, K2, V2> function
Null safety
- @Deprecated('Use Map.map or a for loop in a Map literal.')
- Map<
K1, V1> map, - {K2 key(
- K1,
- V1
- V2 value(
- K1,
- 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;
}