Skip to content

Instantly share code, notes, and snippets.

@bhenry
Created November 4, 2010 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenry/662618 to your computer and use it in GitHub Desktop.
Save bhenry/662618 to your computer and use it in GitHub Desktop.
(defn lower-key [x]
(if (or (string? x) (keyword? x))
(-> x name .toLowerCase keyword)
x))
(defn map-keys
"applies f to each key of m. also to keys of m's vals and so on."
[f m]
(zipmap
(map (fn [k]
(f k))
(keys m))
(map (fn [v]
(if (map? v)
(map-keys f v)
v))
(vals m))))
(map-keys lower-key
{:aBaB 123
"CAsasas" {1 "doesn't apply to non-string non-keyword keys"
:yoGURt "mmMMm"
:notVALUES "either"}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment