May 2018
Beginner to intermediate
290 pages
6h 43m
English
Possibly the biggest danger lurking inside of clojure.spec is related to mistyping a keyword while registering a spec. For example, if you do this you might think you are (among other things) declaring that the value associated with :title in a book map needs to be a string:
| | (s/def ::author string?) |
| | |
| | (s/def ::titlo string?) |
| | |
| | (s/def ::copies pos-int?) |
| | |
| | (s/def ::book |
| | (s/keys :req-un [::title ::author ::copies])) |
| | |
| | ;; Register a spec for the find-by-title function. |
| | |
| | (s/fdef find-by-title |
| | :args (s/cat :title ::title |
| | :inventory ::inventory)) |
But take a closer look and you will see that we misspelled ::title when defining the spec. This means that while books are required to have titles, since there is no ...
Read now
Unlock full access