So spec (1) has a list of predicates it can create generators for, so (s/gen int?)
works. I kinda forgot, is it possible to extend this on the predicate level, e.g. can I register a predicate so that this works (s/gen my-predicate?)
?
@lennart.buit You'd have to write your own generator (and then supply it when you define the spec based on your predicate).
Yah right, so I can only define a spec with s/def
and attach a generator that way
I can’t extend like this list: https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/gen/alpha.clj#L146
Yeah right, reason I’m asking, we have quite a lot of specs that use a (non-spec aware) predicate, e.g. (s/def ::my-spec my-predicate?)
. So I was kinda hoping I wouldn’t have to do like:
(s/def ::my-predicate-spec (s/with-gen my-predicate? (fn [] ...))
(s/def ::my-spec ::my-predicate-spec)
But what I’m finding in the source, I appear to be out of luckyeah, this is not currently an open set
I think the issue is that if you could extend it, then predicates may gen in one place but not in another if you didn't extend it the same way (somewhat reminiscent of reader macros).
Right — because you have this global idea of what generators exists for what predicates and that could clash, or not be loaded or … Yeah I can see that as causing pains