Created
March 1, 2019 05:34
-
-
Save xieyunzi/cffa54a6b96a2b1b2906958a6cbf01f5 to your computer and use it in GitHub Desktop.
if->.clj
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
;; idea from https://stackoverflow.com/questions/11676120/why-dont-when-let-and-if-let-support-multiple-bindings-by-default | |
(defmacro if-> | |
"Use this to avoid `if else nested hell`. | |
(if-> [true (prn 1) (prn 2) true (prn 3) (prn 4) false (prn 5) (prn 6)])" | |
[bindings] | |
(if (seq bindings) | |
`(if ~(first bindings) | |
(let [r# ~(second bindings)] | |
(or (if-> ~(vec (drop 3 bindings))) | |
r#)) | |
~(first (next (next bindings)))) | |
nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment