toggle method

IMapOfSets<K, V> toggle(
  1. K key,
  2. V value, {
  3. bool? state,
})

Removes the value from the set of the corresponding key, if it exists in the set. Otherwise, adds it to the set. If the key doesn't exist, it will be created and then have the new value added to the new, corresponding set.

However, if can force the value to be added or removed by providing state true or false.

Implementation

IMapOfSets<K, V> toggle(K key, V value, {bool? state}) =>
    (state ?? !contains(key, value)) ? add(key, value) : remove(key, value);