Skip to content

Instantly share code, notes, and snippets.

@jmgimeno
Created May 11, 2011 12:55
Show Gist options
  • Save jmgimeno/966404 to your computer and use it in GitHub Desktop.
Save jmgimeno/966404 to your computer and use it in GitHub Desktop.
Get All Nested Map Values (N levels deep)
(def my-data {"Jay"
{"clojure"
{:name "Jay", :language "clojure", :enjoys true},
"ruby"
{:name "Jay", :language "ruby", :enjoys true}}
"Jon"
{"java"
{:name "Jon", :language "java", :enjoys true}}} )
(defn nth-vals* [a i m]
(if (and (map? m) (> i 0))
(reduce into a (map (fn [v] (nth-vals* a (dec i) v)) (vals m)))
(conj a m)))
(defn nth-vals [i m]
(if (nil? m)
{}
(nth-vals* [] i m)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment