symbol?
This document defines the specification language which is the foundation of the spec library. The specification language consists of all valid specs.
A spec itself describes a set of allowed values. For example the spec int?
describes the set of all integers.
Code examples assume that the namespace alias s refers to clojure.spec.alpha .
|
The simplest form of specs are predicates which are symbols which bind to predicate functions at runtime. Predicate functions are functions with a single argument that return a boolean.
symbol?
int?
double?
string?
The and-form
takes a possibly empty sequence of specs. Specs are validated in order. Validation results probagate from left to right. The empty and-form
validates any value.
(s/cat :s #{s/and} :args (s/* ::spec))
(s/and int? pos?)
The or-form
takes a possibly empty sequence of choices, each annotated with a tag. Specs of each choice are tried in order. The empty or-form
doesn’t validate any value.
(s/cat :s #{s/or} :args (s/* (s/cat :tag keyword? :spec ::spec)))
Replaced :pred with :spec here because the or-form excepts arbitrary specs instead of only predicates.
|
(s/or :int int? :dbl double?)
(s/cat :s #{s/keys} :args (s/keys* :opt-un [::req ::req-un ::opt ::opt-un ::gen]))
The merge-form
takes a possibly empty sequence of map-validating specs (e.g. keys-forms
) and validates values which are valid in all specs.
(s/cat :s #{s/merge} :args (s/* ::spec))
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close