Created
January 18, 2018 08:47
-
-
Save visibletrap/d911d4734ca4915a916ae03628f7adbd 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 collify [x-or-coll] | |
(if (coll? x-or-coll) | |
x-or-coll | |
[x-or-coll])) | |
(defn keyword->symbol [k] | |
(symbol (name k))) | |
(defmacro expand-set-values | |
[attributes] | |
(let [ks (keys attributes)] | |
`(into [] | |
(for | |
~(into [] (mapcat (juxt (comp keyword->symbol first) (comp collify second)) attributes)) | |
~(into {} (mapv vector ks (map keyword->symbol ks))))))) | |
(comment | |
(expand-set-values {:k1 [:v1 :v2] | |
:k2 :v3 | |
:k3 [:v4 :v5 :v6]}) | |
(macroexpand-1 | |
`(expand-set-values {:k1 [:v1 :v2] | |
:k2 :v3 | |
:k3 [:v4 :v5 :v6]}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment