Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Spec by

Using Spec 1, it looks like the count validation failure could be reported better - it's not clear what the actual count was

user=> (s/assert (s/coll-of any? :count 1)
            [])
Execution error - invalid arguments to user/eval148 at (REPL:1).
[] - failed: (= 1 (count %))

1 Answer

0 votes
by

:count uses bounded-count which works just fine with infinite collections. Reporting the actual count would require using count which hangs on infinite collections.

by
Fair observation! However one could detect whether the case is easily tractable, e.g. is the coll a vector?

Which of course isn't a generalized solution, but could satisfy a large majority of practical use cases.
by
A few more things worth pointing out:
- There are other qualifiers apart from `:count`
- The "Execution error" above actually prints the value itself, so it's trivial to see the count
- The above leads to a hang on infinite collections, oops
- Surprisingly, `explain-data` also hangs on infinite collections - I think it's a bug
by
Thanks, I appreciate the observations. I disagree on  "[...] actually prints the value itself, so it's trivial to see the count".

It's not trivial for a human to count 42 or 1024 items in a vector :) spec explanations should be there to make our lives easier.
...