Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created January 10, 2013 04:07
Show Gist options
  • Save gtrak/4499370 to your computer and use it in GitHub Desktop.
Save gtrak/4499370 to your computer and use it in GitHub Desktop.
(defmacro let-map
"Avoids having to build maps from let bindings manually"
[bindings]
(let [names (->> (take-nth 2 bindings)
(tree-seq #(or (sequential? %) (map? %)) identity)
(filter symbol?)
(into #{})) ; dumps it all into a set
bindings (destructure bindings)]
`(let [~@bindings]
(zipmap [~@(map keyword names)]
[~@names]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment