On Thu, Mar 22, 2012 at 10:32 PM, Cedric Greevey <cgree...@gmail.com> wrote:
(into #{} (remove #(= (:id %) foo) input-set))

> You could stop when :id foo got hit by using a loop/recur, and save half the
> iterations on average.

Clarification: stop comparing to match the :id key against the target.
You'd have to continue copying into the output, of course.

The map approach makes it easy via (dissoc the-map foo), as well as to
look up by id.

All of this also assumes that the :id numbers are unique. If they're
not, the map approach needs modifying, to e.g.

{:id 1 [{:id 1, :foo "bar"} {:id 1, :foo "baz"}], :id 2 [{:id 2, :foo "car"}]}

where each value is a bucket of potentially more than one object.

The removal algorithm likewise needs changing if the object is not to
remove ALL items with the target :id. If it's a specific item, you
need to find it in the bucket and remove it using a criterion beyond
the :id (and in the set case, just make the remove closure's test more
specific).

-- 
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

Reply via email to