Returns the first logical true value of (pred x) for any x in coll,
else nil. One common idiom is to use a set as pred, for example
this will return :fred if :fred is in the sequence, otherwise nil:
(some #{:fred} coll)
;; some can be used as a substitute for (first (filter ... ;; in most cases user=> (first (filter even? [1 2 3 4])) 2 user=> (some #(if (even? %) %) [1 2 3 4]) 2 user=>
(defn some
"Returns the first logical true value of (pred x) for any x in coll,
else nil. One common idiom is to use a set as pred, for example
this will return :fred if :fred is in the sequence, otherwise nil:
(some #{:fred} coll)"
{:added "1.0"
:static true}
[pred coll]
(when (seq coll)
(or (pred (first coll)) (recur pred (next coll)))))
Comments top
1 comment(s) for some.
Be careful about using sets as predicates if you don't know what is in the set. In particular,
(#{nil} nil)is and(#{false} false)is Consider using instead.(#{nil} nil)is and(#{false} false)is Consider using instead.