putAll method
Adds all entries in other
to this map, using resolve
to resolve conflicting entries.
See merge for merging maps without mutating this map.
final foo = {'a': 1, 'b': 2};
final bar = {'a': 1, 'b': 3};
foo.merge(bar, resolve: (k, v1, v2) => min(v1, v2));
print(foo); // {'a': 1, 'b': 2}
Implementation
void putAll(Map<K, V> other, {required V Function(K key, V existing, V other) resolve}) {
for (final MapEntry(:key, :value) in other.entries) {
final existing = this[key];
this[key] = existing == null ? value : resolve(key, existing, value);
}
}