-
-
Save tomjack/2f060dde83ac1bfbe551 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
(defmacro let-into [to & bindings] | |
`(let [~@bindings] | |
(into ~to ~(vec (for [sym (take-nth 2 bindings)] | |
[(keyword sym) sym]))))) | |
(comment | |
(let-into {} | |
x 1 | |
y (inc x) | |
z (inc y)) | |
expands to: | |
(let [x 1 | |
y (inc x) | |
z (inc y)] | |
(into {} [[:x x] [:y y] [:z z]])) | |
returning: | |
{:x 1 :y 2 :z 3} | |
with (defrecord Foo [x y]) we get: | |
(let-into (Foo. 0 0) | |
x 1 | |
y (inc x)) | |
but having to supply a dummy instance is ugly...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment