Staying Out of Trouble

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 ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.