Skip to content

Instantly share code, notes, and snippets.

@noidi
Created March 15, 2010 10:05
Show Gist options
  • Save noidi/332691 to your computer and use it in GitHub Desktop.
Save noidi/332691 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