Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkwatson/2173a9139797e0cf6149 to your computer and use it in GitHub Desktop.
Save mkwatson/2173a9139797e0cf6149 to your computer and use it in GitHub Desktop.
while-> comparison
;; 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