Created
May 11, 2011 12:55
-
-
Save jmgimeno/966404 to your computer and use it in GitHub Desktop.
Get All Nested Map Values (N levels deep)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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