Last active
August 29, 2015 14:08
-
-
Save mkwatson/2173a9139797e0cf6149 to your computer and use it in GitHub Desktop.
while-> comparison
This file contains 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
;; cond-> | |
;; Takes an expression and a set of test/form pairs. Threads expr (via ->) | |
;; through each form for which the corresponding test | |
;; expression is true. Note that, unlike cond branching, cond-> threading does | |
;; not short circuit after the first true test expression. | |
(cond-> 5 | |
true inc | |
false (+ 100) | |
(= 2 2) (/ 2)) | |
;=> 3 | |
;; some-> | |
;; When expr is not nil, threads it into the first form (via ->), | |
;; and when that result is not nil, through the next etc | |
(some-> 5 | |
inc | |
(#(if false (+ % 100))) | |
(#(if true (/ % 2)))) | |
;=> nil | |
(while-> pos? 5 | |
inc | |
(- 100) | |
(+ 1000)) | |
;=> 6 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment