Skip to content

Instantly share code, notes, and snippets.

@peat
Last active August 29, 2015 14:25
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 peat/982ad29845bfb003845b to your computer and use it in GitHub Desktop.
Save peat/982ad29845bfb003845b to your computer and use it in GitHub Desktop.
; 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