A spec defines the expected shape of specific values in Clojure and specs are intended to be used across multiple projects. Specifications for more complex values are composed of specific value specifications, providing a flexible way to define what key parts of the system should look like.
Spec is included in Clojure version 1.9 onward and can be used by requiring the
clojure.spec.alpha in the REPL or in namespaces of a Clojure project.
Purpose of Clojure spec
Example use cases
- API requests (schema is often used here, but so can spec)
- Checking data pulled from / pushed to message systems (e.g. Kafka, TIBCO)
- Data specifications (eg. Vega-lite)
- practicalli/leveraging-spec - basic examples of using spec, following the Practicalli Spec broadcasts
Understanding the basics of Clojure Spec
Why is the spec library called alpha?
The library is called
clojure.spec.alpha as the design of spec is still evolving and there may be some changes to the design in later versions. Clojure aims for backwards compatibility, so new versions typically do not break existing use of libraries.