kwatford
unread,Dec 14, 2008, 3:58:59 PM12/14/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure
So I have some code that looks somewhat like:
(update-in node [:index :x] set/union #{:y})
This seems fine as long as there's already a set in the desired spot.
However, since update-in will kindly build the map structure for you
if it doesn't already exist, I figured it would be nice not to have to
check for nils and replace them with empty sets. So I tried this:
=> (set/union nil #{:foo})
(:foo)
Huh? I checked its class, and it is indeed a list. So I tried:
=> (set/union '(1 2 3 a) '(a b c))
(c b a 1 2 3 a)
=> (set/union [0 1 2 3] [0])
[0 1 2 3 0]
Looking at the source explains this:
(defn union
"Returns a set that is the union of the two sets."
[xset yset]
(reduce conj xset yset))
I don't know if this (and any similar weirdness in the rest of the set
namespace) should be fixed since you aren't really supposed to throw
non-sets in there, but I do think a special case for nil might be nice
here.