Skip to content

Instantly share code, notes, and snippets.

@Morgawr
Last active August 29, 2015 13:55
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 Morgawr/8687711 to your computer and use it in GitHub Desktop.
Save Morgawr/8687711 to your computer and use it in GitHub Desktop.
(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