addAllIfEmpty method
Add others
to Map.
Keys in others
that are already in Map will not be added.
Mapにothers
を追加します。
others
のキーの中でMapの中にすでにあるものは追加されません。
final map = {"a": 1, "b": 2, "c": 3};
final others = {"c": 4, "d": 5};
map.addAllIfEmpty(others); // {"a": 1, "b": 2, "c": 3, "d": 5}
Implementation
void addAllIfEmpty(Map<K, V>? others) {
if (others.isEmpty) {
return;
}
for (final tmp in others!.entries) {
if (containsKey(tmp.key)) {
continue;
}
this[tmp.key] = tmp.value;
}
}