-
-
Save peat/982ad29845bfb003845b to your computer and use it in GitHub Desktop.
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
; I love the thread macro ... but sometimes I want to abort the chain of execution. | |
(-> some-data | |
transformation-a | |
transformation-b ; returns false, and I don't want to run the others! | |
transformation-c | |
transformation-d) | |
; ... for example, if the result of one of the functions is falsey, don't continue | |
(bool-> some-data | |
transformation-a | |
transformation-b ; returns false, so transformation-c and -d are never run | |
transformation-c | |
transformation-d) | |
; ... or even better yet, let me define a function that is run after every step in the chain, | |
; and determines if execution continues. | |
(defn continue? [x] ( ... )) | |
(cond-> some-data | |
continue? | |
transformation-a | |
transformation-b ; returns a value that continue? decides should halt further execution | |
transformation-c | |
transformation-d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment