May 2018
Beginner to intermediate
290 pages
6h 43m
English
One issue with more complex specs is that it’s not always immediately clear why a particular value doesn’t match. For example, you might have to look at this expression for a while to see why valid? returns false:
| | (s/valid? ::book {:author :austen :title :emma}) |
To help you figure out why your spec isn’t matching, clojure.spec provides the explain function, which takes the same arguments as valid?. If the spec matches, explain will print a celebratory message, so that if you do this:
| | (s/explain n-gt-10 44) |
you will see this:
| | Success! |
Things are much more interesting if the spec doesn’t match. Do this:
| | (s/explain n-gt-10 1) |
and you will see something like the following:
| | val: 4 fails predicate: (> % 10) |
Thus we can use ...
Read now
Unlock full access