merge method

Map<K, V> merge(
  1. Map<K, V>? others, {
  2. K convertKeys(
    1. K key
    )?,
  3. V convertValues(
    1. V value
    )?,
})

Merges the map in others with the current map.

If the same key is found, the value of others has priority.

Implementation

Map<K, V> merge(
  Map<K, V>? others, {
  K Function(K key)? convertKeys,
  V Function(V value)? convertValues,
}) {
  others ??= const {};
  final res = <K, V>{};
  for (final tmp in entries) {
    res[tmp.key] = tmp.value;
  }
  for (final tmp in others.entries) {
    final key = convertKeys?.call(tmp.key) ?? tmp.key;
    final value = convertValues?.call(tmp.value) ?? tmp.value;
    res[key] = value;
  }
  return res;
}