Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created November 8, 2011 00:40
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AlexBaranosky/1346666 to your computer and use it in GitHub Desktop.
first-truthy-fn
(defn first-truthy-fn
"Returns the first function in a seq of functions
that evaluates to truthy for the given arguments"
[all-preds & args]
(loop [[p & more-ps] all-preds]
(when p
(if (apply p args) p (recur more-ps)))))
;; filter version that fails to be lazy:
(defn first-truthy-fn [preds & args]
(first (filter #(apply % args) preds)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment