-
-
Save fivejjs/0fce4813fc88666b84fd8cde4b63e77b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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