addWith method
Set only the value of the key specified
by keys
in the map specified by other
.
final main = {"c": 3, "d": 4};
final other = {"a": 1, "b": 2};
main.addWith(other, ["a"]); // {"a": 1, "c": 3, "d": 4}
Implementation
Map<K, V> addWith(Map<K, V> other, Iterable<K> keys) {
for (final key in keys) {
if (!other.containsKey(key)) {
continue;
}
// ignore: null_check_on_nullable_type_parameter
this[key] = other[key]!;
}
return this;
}