public
Created

first-truthy-fn

  • Download Gist
gistfile1.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12
(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)))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.