toggle

fun <T> MutableSet<T>.toggle(element: T): Boolean

Adds element if absent or removes it if present, and returns whether the set contains it afterwards.

Returns true when the element was added, false when it was removed.