Last active
October 13, 2015 19:02
-
-
Save commondatageek/91a4742f30becf5890ec to your computer and use it in GitHub Desktop.
while-let: Keep looping while let bindings are truthy
This file contains hidden or 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 while-let | |
"While all bindings are truthy, execute body. Useful for draining | |
channels, buffers, anything that can be read, etc." | |
[bindings & body] | |
(let [pairs (partition 2 bindings) | |
test-exprs (map second pairs) | |
test-vals (map first pairs)] | |
`(loop ~bindings | |
(if (and ~@test-vals) | |
(do | |
~@body | |
(recur ~@test-exprs)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment