Skip to content

Instantly share code, notes, and snippets.

@bsless
Created October 10, 2020 11:49
Show Gist options
  • Save bsless/7afefc2b8cbec624e30721781c6740d9 to your computer and use it in GitHub Desktop.
Save bsless/7afefc2b8cbec624e30721781c6740d9 to your computer and use it in GitHub Desktop.
(defmacro defnormalizer
[name m]
{:pre (map? m)}
(let [arg 'rec
body
(reduce-kv
(fn [m k v]
((if (sequential? v) assoc-in assoc)
m
v
(if (sequential? k)
`(-> ~arg ~@k)
`(~arg ~k))))
{}
m)]
`(defn ~name
[~arg]
~body)))
(defnormalizer
foo
{:a :A
:foo [:bar :bazz]
:fizz [:bar :buzz]
::B
[:x :y] :z})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment