Skip to content

Instantly share code, notes, and snippets.

@brapse
Created May 16, 2014 14:42
Show Gist options
  • Save brapse/7be90ed2ae14099d57c4 to your computer and use it in GitHub Desktop.
Save brapse/7be90ed2ae14099d57c4 to your computer and use it in GitHub Desktop.
Flatten a clojure map
(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