Skip to content

Instantly share code, notes, and snippets.

@xieyunzi
Created March 1, 2019 05:34
Show Gist options
  • Save xieyunzi/cffa54a6b96a2b1b2906958a6cbf01f5 to your computer and use it in GitHub Desktop.
Save xieyunzi/cffa54a6b96a2b1b2906958a6cbf01f5 to your computer and use it in GitHub Desktop.
if->.clj
;; 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