tree-seq makes this pretty simple:

(defn nested-vals [key coll]
  (for [x (tree-seq coll? seq coll) :when (contains? x key)]
    (get x key)))

This works with any type of key and all associative Clojure
structures. It could be made compatible with Java structures by
swapping out the 'coll?' predicate for something more general.

Justin

On Dec 5, 9:12 pm, Alex Baranosky <alexander.barano...@gmail.com>
wrote:
> Hi guys,
>
> I would like a function to be able to take an arbitrarily nested collection
> and return a sequence of all values of a given key, such as :name, that
> appears anywhere in the nested collection.
>
> Does anything like this already exist?
>
> Thanks for the help,
> Alex

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