Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Collections by
retagged by

Is there a particular reason why clojure.set does not provide a symmetric-difference function?

It seems a relatively frequent thing to want.

`(s/difference (s/union a b) (s/intersection a b))` - but presumably this has sub-optimal performance?
clojure.data/diff, then combine the only-a and only b thirds

1 Answer

0 votes

Can't remember anyone ever asking for it...

For things like this, I usually look to whether it pops up in utility libraries and how frequently its used. Do you have any data from that?

https://grep.app/search?q=symmetric-difference&filter[lang][0]=Clojure doesn't turn up much, but name might be something else of course.
We have multiple instances of `(set/difference (set/union a b) (set/intersection a b))` in our codebase but don't have it under a specific name.
edited by
I could also find:


Besides from that, I would consider that:

* This is pretty basic operation on sets
* Not everyone comprehensively knows set theory
* Sometimes people imagine they could do X, but don't, if there's no readily available solution
* By offering this op, people can discover/remember that they can possibly want such a thing

The last point being the most important: people won't use (or think of using) things they aren't familiar with. So Clojure can help teaching/reminding these classic concepts.

Otherwise, the lack of popularity can also be considered sort of a self-fulfilling prophecy?
Well it exists here now to garner interest.