every

added

ns
clojure.spec

type
macro

(every pred & {:keys [into kind count max-count min-count distinct gen-max gen], :as opts})

takes a pred and validates collection elements against that pred.

Note that 'every' does not do exhaustive checking, rather it samples
*coll-check-limit* elements. Nor (as a result) does it do any
conforming of elements. 'explain' will report at most *coll-error-limit*
problems.  Thus 'every' should be suitable for potentially large
collections.

Takes several kwargs options that further constrain the collection:

:kind - a pred/spec that the collection type must satisfy, e.g. vector?
(default nil) Note that if :kind is specified and :into is
not, this pred must generate in order for every to generate.
:count - specifies coll has exactly this count (default nil)
:min-count, :max-count - coll has count (<= min-count count max-count) (defaults nil)
:distinct - all the elements are distinct (default nil)

And additional args that control gen

:gen-max - the maximum coll size to generate (default 20)
:into - one of [], (), {}, #{} - the default collection to generate into
(default: empty coll as generated by :kind pred if supplied, else [])

Optionally takes :gen generator-fn, which must be a fn of no args that
returns a test.check generator

See also - coll-of, every-kv

                (require '[clojure.spec :as s])

;;is every element a keyword?
(s/valid? (s/every keyword?) [:b :c :d])
;;;true

;;is collection a vector?
(s/valid? (s/every keyword? :kind vector?) [:b :c :d])
;;true

;;is every element between 5 and 10
(s/valid? (s/every #(and (> 10 %) (< 5 %))) [6 7 8])
;;true

(s/valid? (s/every #(and (> 5 %) (< 10 %))) [6 7 1])
;;false