Fork me on GitHub
#clojure-spec
<
2018-04-24
>
ouvasam09:04:36

Hi, With clojure.spec, Is there a way to get all the errors with s/and instead of having only the first one ? e.g.

``
(s/explain (s/and int? even? #(> % 1000)) 9)
;; val: 9 fails predicate: even?
`` Is it possible to also have the last predicate error ? (> % 1000) Many Thanks

Alex Miller (Clojure team)12:04:34

In this case, no. Because s/and flows values through if an earlier one fails it can’t run a later one

ouvasam12:04:30

Thanks. Is there another way to get all the errors ?

Alex Miller (Clojure team)13:04:57

not without breaking apart the s/and into pieces and running each individually

xiongtx17:04:29

Is there a way to express the idea that a spec is any subset of some provided set, and to have generator behave accordingly?

misha17:04:18

@xiongtx something like:

(s/def :foo/item #{:a :b :c})
(s/def :foo/items (s/coll-of :foo/item :kind set?))
or just
(s/coll-of #{:a :b :c} :kind set?)

👍 4
xiongtx17:04:24

:thumbsup: