Skip to content

Instantly share code, notes, and snippets.

@dakrone
Created January 29, 2013 01:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakrone/485ad11b922598c0c77c to your computer and use it in GitHub Desktop.
Save dakrone/485ad11b922598c0c77c to your computer and use it in GitHub Desktop.
(defmulti recur-replace-keys (comp type first list))
(defmethod recur-replace-keys java.util.Map [mp pat rep]
(zipmap (map #(if (keyword? %)
(keyword (.replaceAll (name %) pat rep))
(recur-replace-keys % pat rep))
(keys mp))
(map #(recur-replace-keys % pat rep) (vals mp))))
(defmethod recur-replace-keys :default [mp pat rep] mp)
(defmethod recur-replace-keys clojure.lang.IPersistentCollection [s pat rep]
(into (empty s) (map #(recur-replace-keys % pat rep) s)))
(prefer-method recur-replace-keys java.util.Map
clojure.lang.IPersistentCollection)
(defmethod recur-replace-keys clojure.lang.ISeq [s pat rep]
(map #(recur-replace-keys % pat rep) s))
(defn dasherize-keys
"{:map_like 'this} to {:map-like 'this}"
[m]
(recur-replace-keys m "_" "-"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment