You're viewing version 1.2.0 of some. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (some pred coll)
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)

8 Examples top

  • user=> (some even? '(1 2 3 4))
    true
    user=> (some even? '(1 3 5 7))
    nil
  • user=> (some true? [false false false])
    nil
    user=> (some true? [false true false])
    true
    user=> (some true? [true true true])
    true
    
  • user=> (some #(= 5 %) [1 2 3 4 5])
    true
    user=> (some #(= 5 %) [6 7 8 9 10])
    nil
  • user=> (some #(when (even? %) %) '(1 2 3 4))
    2
  • user=> (some {2 "two" 3 "three"} [nil 3 2])
    "three"
  • ;; 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=>
  • ;; find a whether a word is in a list of words.
    (def word "foo")
    (some (partial = word) words)
  • user=> (some #{2} (range 0 10))
    2
    
    user=> (some #{200} (range 0 10))
    nil
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2045 top

(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"}
  [pred coll]
    (when (seq coll)
      (or (pred (first coll)) (recur pred (next coll)))))
Vars in clojure.core/some: defn first next or seq when

Comments top

No comments for some. Log in to add a comment.