addAllIfEmpty method

void addAllIfEmpty(
  1. Map<K, V>? others
)

Add others to Map.

Keys in others that are already in Map will not be added.

Mapothersを追加します。

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;
  }
}