store/[org.clojure/clojure "1.8.0"] clj::clojure.core/some-fn

Official Documentation

Add notes
Arities
==================================================
   [p]
   [p1 p2]
   [p1 p2 p3]
   [p1 p2 p3 & ps]

Docstring
==================================================
  Takes a set of predicates and returns a function f that returns the first logical true value
  returned by one of its composing predicates against any of its arguments, else it returns
  logical false. Note that f is short-circuiting in that it will stop execution on the first
  argument that triggers a logical true result against the original predicates.

Source

(defn some-fn
  "Takes a set of predicates and returns a function f that returns the first logical true value
  returned by one of its composing predicates against any of its arguments, else it returns
  logical false. Note that f is short-circuiting in that it will stop execution on the first
  argument that triggers a logical true result against the original predicates."
  {:added "1.3"}
  ([p]
     (fn sp1
       ([] nil)
       ([x] (p x))
       ([x y] (or (p x) (p y)))
       ([x y z] (or (p x) (p y) (p z)))
       ([x y z & args] (or (sp1 x y z)
                           (some p args)))))
  ([p1 p2]
     (fn sp2
       ([] nil)
       ([x] (or (p1 x) (p2 x)))
       ([x y] (or (p1 x) (p1 y) (p2 x) (p2 y)))
       ([x y z] (or (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z)))
       ([x y z & args] (or (sp2 x y z)
                           (some #(or (p1 %) (p2 %)) args)))))
  ([p1 p2 p3]
     (fn sp3
       ([] nil)
       ([x] (or (p1 x) (p2 x) (p3 x)))
       ([x y] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y)))
       ([x y z] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z)))
       ([x y z & args] (or (sp3 x y z)
                           (some #(or (p1 %) (p2 %) (p3 %)) args)))))
  ([p1 p2 p3 & ps]
     (let [ps (list* p1 p2 p3 ps)]
       (fn spn
         ([] nil)
         ([x] (some #(% x) ps))
         ([x y] (some #(or (% x) (% y)) ps))
         ([x y z] (some #(or (% x) (% y) (% z)) ps))
         ([x y z & args] (or (spn x y z)
                             (some #(some % args) ps)))))))

Example 1

Edit
;; `some-fn` is useful for when you'd use `some` (to find out if any
;; values in a given coll satisfy some predicate), but have more than
;; one predicate. For example, to check if any values in a coll are
;; either even or less than 10:

(or (some even? [1 2 3])
    (some #(< % 10) [1 2 3]))

;; but `some-fn` can save you some duplication here:

((some-fn even? #(< % 10)) 1 2 3)

;; Minor note: the former returns nil if it doesn't find
;; what it's looking for. The latter returns false.

Example 2

Edit
((some-fn even?) 1)
;; => false

((some-fn even?) 2)
;; => true

((some-fn even?) 1 2)
;; => true

Example 3

Edit
;;; http://en.wikipedia.org/wiki/Fizz_buzz
(def fizzbuzz
  (some-fn #(and (= (mod % 3) 0) (= (mod % 5) 0) "FizzBuzz")
           #(and (= (mod % 3) 0) "Fizz")
           #(and (= (mod % 5) 0) "Buzz")))

(doseq [n (take 17 (rest (range)))]
  (println (or (fizzbuzz n) n)))

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17

Uses on crossclj