merge method

  1. @override
ImmortalMap<K, V> merge(
  1. ImmortalMap<K, V> other
)

Returns a copy of this map where all key/value pairs of other are added and merged with existing values if possible.

If the value type V is Mergeable and a key is present in both maps, the resulting map will contain the merged result of the two respective values for this key.

Otherwise the function behaves like addAll, i.e. if a key of other is already present in this map, its value is overwritten in the copy.

If other is empty, the map is returned unchanged.

Implementation

@override
ImmortalMap<K, V> merge(ImmortalMap<K, V> other) => other.isEmpty
    ? this
    : updateAll((k, v) => other[k]
        .map(
            (otherValue) => v is Mergeable ? v.merge(otherValue) : otherValue)
        .orElse(v)).addAll(other.removeAll(keys));