Skip to content

Instantly share code, notes, and snippets.

@timmc
Created February 16, 2011 16:03
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 timmc/829621 to your computer and use it in GitHub Desktop.
Save timmc/829621 to your computer and use it in GitHub Desktop.
; 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