Skip to content

Instantly share code, notes, and snippets.

@nipra
Created May 4, 2010 10:49
Show Gist options
  • Save nipra/389253 to your computer and use it in GitHub Desktop.
Save nipra/389253 to your computer and use it in GitHub Desktop.
(defn map-keys
"Applies f to all keys of m recursively."
[f m]
(cond
(map? m) (into {} (map (fn [[key value]]
[(f key) (map-keys f value)])
m))
(coll? m) (map (partial map-keys f) m)
:default m))
(comment (map-keys keyword {"a" 1 "b" [{"c" 1}]}))
; => {:a 1, :b ({:c 1})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment