On Sep 1, 7:35 pm, Conrad <[email protected]> wrote:
> Hi everyone! I was wondering if there was a better idiom in Clojure
> for filtering items from a map... Suppose we want to remove all items
> from a map that have an odd number as a value. Here's how I'd write
> it:

I like to use "reduce" for processing maps:

(reduce
  (fn [result [key value]]
    (if (even? value)
        (assoc result key value)
        result))
  {}
  {:dog 5 :cat 4 :mouse 7 :cow 6})

This is slightly more efficient than (into {} ...), although
transients may soon change that.

-SS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to