Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Last active August 29, 2015 14:07
Show Gist options
  • Save martintrojer/d438e26dfcb0166aef8c to your computer and use it in GitHub Desktop.
Save martintrojer/d438e26dfcb0166aef8c to your computer and use it in GitHub Desktop.
kebab-case keywords in nested data-structures
(ns kebab
(:require [camel-snake-kebab :as kebab]
[schema.coerce :as c]
[schema.core :as s]))
(def Data (s/either s/Keyword
{(s/recursive #'Data) (s/recursive #'Data)}
[(s/recursive #'Data)]
#{(s/recursive #'Data)}
s/Any))
(def ->kebab-keys-coercer
(c/coercer Data {s/Keyword (coerce/safe #(kebab/->kebab-case %))}))
(def ->snake-keys-coercer
(c/coercer Data {s/Keyword (coerce/safe #(kebab/->snake_case %))}))
(->kebab-keys-coercer {[:f_o_o] :a_b :b_a_r {:b_a_z {:y_z #{'([:y_e_s])}}}})
;; => {[:f-o-o] :a-b :b-a-r {:b-a-z {:y-z #{[[:y-e-s]]}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment