May 2018
Beginner to intermediate
290 pages
6h 43m
English
So far in our examples we have been treating specs like the garden-variety Clojure values that they are. But consider how useful it would be to have a global registry, a place where you could announce, When I’m talking about books I mean a map with :title, :author, and :copies keys. That way any bit of code anywhere can check to see if a value qualifies as a book according to the high standards of our book inventory system.
This is the motivation behind clojure.spec/def, not to be confused with our old buddy clojure.core/def! The idea of clojure.spec/def is to allow you to register your spec in a JVM-wide registry of specs any code can then use. For example, this:
| | (s/def |
| | :inventory.core/book |
| | (s/keys |
| | :req-un |
| | [:inventory.core/title ... |
Read now
Unlock full access