Last active
August 29, 2015 13:55
-
-
Save Morgawr/8687711 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-keys [bindings & body] | |
(let [into-keys (fn [[k v]] [{:keys k} v]) | |
key-bindings (->> bindings | |
(partition-all 2) | |
(mapcat into-keys))] | |
`(let [~@key-bindings] ~@body))) | |
(def my-map { :var1 1 | |
:another 2 | |
:hello "world" }) | |
(let [{:keys [var1 another hello]} my-map] | |
(println var1 another hello)) | |
; vs | |
(let-keys [[var1 another hello] my-map] | |
(println var1 another hello)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment