merge method

Map<K, V> merge(
  1. Map<K, V>? other
)

Merges the current map with another map. If there are duplicate keys, the values from the other map will overwrite those in the current map. If other is null, the current map is returned unchanged.

Example usage:

void main() {
  Map<String, int> map1 = {
    'a': 1,
    'b': 2,
  };

  Map<String, int> map2 = {
    'b': 3,
    'c': 4,
  };

  Map<String, int> mergedMap = map1.merge(map2);
  print(mergedMap); // Output: {a: 1, b: 3, c: 4}
}

Implementation

Map<K, V> merge(Map<K, V>? other) => {...this}..addEntries(other?.entries ?? {});