You're viewing version 1.2.0 of every?. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

every?

clojure.core

  • (every? pred coll)
Returns true if (pred x) is logical true for every x in coll, else
false.

3 Examples top

  • user=> (every? even? '(2 4 6))
    true
    user=> (every? even? '(1 2 3))
    false
  • ;; you can use every? with a set as the predicate to return true if 
    ;; every member of a collection is in the set
    user=> (every? #{1 2} [1 2 3])
    false
    user=> (every? #{1 2} [1 2])
    true
    
    ;; or use a hash-map as the predicate with every? to return true 
    ;; if every member of a collection is a key within the map
    user=> (every? {1 "one" 2 "two"} [1 2])
    true
    user=> (every? {1 "one" 2 "two"} [1 2 3])
    false
  • ;; this is kind of weird IMO... but it works that way (the same for vectors)
    user=> (every? true? '())
    true
    user=> (every? false? '())
    true
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:2026 top

(defn every?
  "Returns true if (pred x) is logical true for every x in coll, else
  false."
  {:tag Boolean
   :added "1.0"}
  [pred coll]
  (cond
   (nil? (seq coll)) true
   (pred (first coll)) (recur pred (next coll))
   :else false))
Vars in clojure.core/every?: cond defn first next nil? seq

Comments top

No comments for every?. Log in to add a comment.