Yup: select-keys

user=> (select-keys {:a 1 :b 2 :c 3} [:a :c])
{:c 3, :a 1}

Regards,
Tim.

On Feb 13, 8:01 pm, Adrian Cuthbertson <adrian.cuthbert...@gmail.com>
wrote:
> Hi,
>
> I have had need of a "sub" hash map function and implemented it as follows;
>
> (defn sub-hashmap
> "Return a sub map of hmap containing the specified keys."
>  [hmap & ks]
> (reduce (fn [mm k] (assoc mm k (k hmap))) {} ks))
>
> (sub-hashmap {:a 1 :b 2 :c 3} :a :c)
> ;=> {:c 3, :a 1}
>
> Is there a similar existing function or a more idiomatic way of doing this?
>
> Thanks, Adrian.
--~--~---------~--~----~------------~-------~--~----~
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
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