2

I find myself in need a function that is similar to some-fn but combines predicates that take multiple arguments.

The new function should take a set of predicates and return a function f. The function f should return the first logical true value returned by one of its composing predicates applied to all of f's arguments, or else logical false. So I should be able to do this:

((some-fn* < >) 1 2)
=> truthy

((some-fn* < >) 1 1)
=> falsey

It's easy enough to implement:

(defn some-fn* [& fs]
  (fn [& args] (loop [fs fs]
                 (when (seq fs)
                   (or (apply (first fs) args)
                       (recur (rest fs)))))))

But it seems like such a simple thing should already exist in clojure.core. Does it? Or is there a simpler way to achieve what I need?

0

1 Answer 1

2

You can use some:

(defn some-fn* [& ps]
  (fn [& args]
    (some #(apply % args) ps)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.