On Wed, Mar 21, 2012 at 5:00 PM, Leandro Oliveira <lolive...@gmail.com> wrote: > Hi all, > > I have a set of hash like this: > > #{{:id 1, :foo "bar"} {:id 2, :foo "car"}} > > and I'd like to remove an item based on its id value. > > Unfortunately, disj requires that I pass the whole map as key to remove it. > > Can I remove the map from the set only using the id? > > My intention is to avoid a lookup on set to get the whole map back. > > Any suggestions?
The only way immediately apparent to me is (into #{} (remove #(= :id foo) input-set)), but that iterates over the whole set. You could stop when :id foo got hit by using a loop/recur, and save half the iterations on average. I suggest a redesign instead: replace the set with a map. Your example above would become: {1 {:id 1, :foo "bar"}, 2 {:id 2, :foo "car"}} -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en