toggle method

bool toggle(
  1. T item
)

If the item doesn't exist in the set, add it and return true. Otherwise, if the item already exists in the set, remove it and return false.

Implementation

bool toggle(T item) {
  var result = contains(item);
  if (result)
    remove(item);
  else
    add(item);
  return !result;
}