Created
May 16, 2014 14:42
-
-
Save brapse/7be90ed2ae14099d57c4 to your computer and use it in GitHub Desktop.
Flatten a clojure map
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
(defn map-flatten | |
([m] (map-flatten m [] [])) | |
([todo keys collection] | |
(if (empty? todo) | |
collection | |
(let [[k v] (first todo)] | |
(if (map? v) | |
(concat (map-flatten v | |
(conj keys k) | |
collection) | |
(map-flatten (into {} (rest todo)) | |
keys | |
collection)) | |
(map-flatten (into {} (rest todo)) | |
keys | |
(conj collection (conj keys k v)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment