clojure clojure.spec Using a predicate as a spec


Any predicate function can be used as a spec. Here's a simple example:

(clojure.spec/valid? odd? 1)
;;=> true

(clojure.spec/valid? odd? 2)
;;=> false

the valid? function will take a spec and a value and return true if the value conforms to the spec and false otherwise.

One other interesting predicate is set membership:

(s/valid? #{:red :green :blue} :red) 
;;=> true