Skip to content

Instantly share code, notes, and snippets.

@jeremyheiler
Created September 11, 2014 12:38
Show Gist options
  • Save jeremyheiler/fe9256e540121e771285 to your computer and use it in GitHub Desktop.
Save jeremyheiler/fe9256e540121e771285 to your computer and use it in GitHub Desktop.
(defn decode-key
"Converts a train case string into a snake case keyword."
[s]
(keyword (str/replace s "_" "-")))
(defn encode-key
"Converts a snake case keyword into a train case string."
[k]
(str/replace (name k) "-" "_"))
(defn transform-keys
"Recursively transforms all map keys in coll with the transform-key fn."
[transform-key coll]
(letfn [(transform [x] (if (map? x)
(into {} (map (fn [[k v]] [(transform-key k) v]) x))
x))]
(walk/postwalk transform coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment