toggle method

bool toggle(
  1. T item
)

If the item does not exist in the list, add it and return true. If it already exists, remove the first instance of it and return false.

Implementation

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