updateAndJoin method

Map<K, V> updateAndJoin(
  1. Map<K, V>? map
)

Merges this map with another map. If a key already exists, the new map's value overrides the existing one.

Example:

Map<String, int>? map1 = {"a": 1, "b": 2};
Map<String, int>? map2 = {"b": 3, "c": 4};
print(map1.updateAndJoin(map2)); // {a: 1, b: 3, c: 4}

Implementation

Map<K, V> updateAndJoin(Map<K, V>? map) {
  if (isNullOrEmpty) return Map<K, V>.from(map ?? {});
  if (map.isNullOrEmpty) return Map<K, V>.from(this!);
  return {...this!, ...map!};
}