This is a construct I come across quite a lot. Is there a nice way to one-line it in Swift?
I could just write an extension on Sequence for it, but I feel like there's a "obvious" higher-order-function / set theory technique that is eluding me.
if array.contains(element) {
array.removeObject(object: element)
}
else {
array.append(element)
}
I don't think the solution will even necessarily be nicer per se, it's just something I think about every time I have to write this.