Skip to content

Instantly share code, notes, and snippets.

@visibletrap
Created January 18, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visibletrap/d911d4734ca4915a916ae03628f7adbd to your computer and use it in GitHub Desktop.
Save visibletrap/d911d4734ca4915a916ae03628f7adbd to your computer and use it in GitHub Desktop.
(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