Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from AlexBaranosky/gist:1346666
Created November 8, 2011 01:15
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 amalloy/1346739 to your computer and use it in GitHub Desktop.
Save amalloy/1346739 to your computer and use it in GitHub Desktop.
first-truthy-fn
;; this works fine
(defn- first-truthy-fn* [[preds & more-preds] args]
(when pred
(if (apply pred args) pred (recur more-preds args))))
(defn first-truthy-fn
"Returns the first function in a seq of functions
that evaluates to truthy for the given arguments -
this shortciruits, only evaluating the functions
it needs to determine a result"
[preds & args]
(first-truthy-fn* preds args))
;; what's wrong with this?
(defn first-truthy-fn [preds & args]
(loop [[p & more-ps] preds]
(when p
(if (apply p args) p (recur more-ps)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment