add method

  1. @useResult
IMapOfSets<K, V> add(
  1. K key,
  2. V value
)

Find the key/set entry, and add the value to the set. If the key doesn't exist, will first create it with an empty set, and then add the value to it. If the value already exists in the set, nothing happens.

Implementation

@useResult
IMapOfSets<K, V> add(K key, V value) {
  final ISet<V> set = _mapOfSets[key] ?? ISetImpl.empty<V>(config.asConfigSet);
  final ISet<V> newSet = set.add(value);
  return set.same(newSet) ? this : replaceSet(key, newSet);
}