Skip to content

Instantly share code, notes, and snippets.

@MayDaniel
Created December 9, 2010 20:14
Show Gist options
  • Save MayDaniel/735261 to your computer and use it in GitHub Desktop.
Save MayDaniel/735261 to your computer and use it in GitHub Desktop.
(defmacro when-lets [[symbol value & more :as bindings] & body]
(if (not-empty bindings)
`(let [tmp# ~value] (when tmp# (let [~symbol tmp#] (when-lets [~@more] ~@body))))
`(do ~@body)))
(defmacro when-lets [bindings & body]
(assert (vector? bindings))
(assert (even? (count bindings)))
(if (not-empty bindings)
(let [[symbol value & more] bindings]
`(when-let [~symbol ~value] (when-lets [~@more] ~@body)))
`(do ~@body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment