Created
February 16, 2011 16:03
-
-
Save timmc/829621 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 needed a way to call a sequence of functions until one returned false, | |
; but return the last true return. | |
(defn changes | |
"Call functions sequentially until one returns false; return true if any returned true. Not tail-recursive." | |
([] false) | |
([f] (f)) | |
([f & fs] | |
(let [fv (f)] | |
(when fv (do (apply changes fs))) | |
fv))) | |
user=> (changes #(+ 2 1) #(println "hello") #(println "never")) | |
hello | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment