mergeWith method
Merges this map with another map using a merge function for conflicts.
Example:
{'a': 1, 'b': 2}.mergeWith({'b': 3, 'c': 4}, (a, b) => a + b);
// {'a': 1, 'b': 5, 'c': 4}
Implementation
Map<K, V> mergeWith(Map<K, V> other, V Function(V, V) mergeFunction) {
final result = <K, V>{...this};
other.forEach((key, value) {
result[key] = result.containsKey(key)
? mergeFunction(result[key] as V, value)
: value;
});
return result;
}