Fork me on GitHub
#clojure-spec
<
2019-10-28
>
Alex Miller (Clojure team)00:10:08

currently, no. we will probably have both flowing and unflowing forms in spec 2

misha07:10:49

you might get away with moving spec to the last position in the s/and, depending on resilience of your predicates to random input. @kenny or, if this is the only place you use predicates – make them expect conformed value

kenny16:10:29

Hmm. Can't do the latter because the predicates are used on the regular form of the data too.

Alex Miller (Clojure team)16:10:09

you could wrap s/nonconforming around each pred

Alex Miller (Clojure team)16:10:44

(s/def ::base-metric
  (s/and
    (s/nonconforming ::metric/metric)
    (s/nonconforming metric-bounds-lower-less-than-or-equal-to-upper?)
    (s/nonconforming metric-default-value-within-bounds?)))

kenny16:10:50

Ah, that's a lot nicer.

kenny16:10:17

That doesn't appear to work for all cases.

kenny16:10:25

Oh, I missed the first one.

kenny16:10:09

This is going to make things so much cleaner! Thanks @alexmiller 😃

(defmacro and2
  [& pred-forms]
  (let [pred-forms (map (fn [pred-form]
                          `(s/nonconforming ~pred-form)) pred-forms)]
    `(s/and ~@pred-forms)))

ataggart17:10:34

Per the description of every, the :kind pred "must generate in order for every to generate". I see that preds like set? can generate, e.g., (gen/sample (s/gen (s/spec set?))), but I'm at a loss as to how to provide generators for custom preds.

Alex Miller (Clojure team)22:10:45

there is no open mechanism to bind generators to custom preds currently

Alex Miller (Clojure team)22:10:30

you can provide the :kind pred as a separate spec outside s/every too (s/and (s/with-gen my-pred ...) (s/every ...))

Alex Miller (Clojure team)22:10:44

that said, what kind of pred are you using that's not a core pred?

ataggart15:10:23

The specific case of wanting to use every over a priority queue.

Alex Miller (Clojure team)15:10:09

prob easier to attach a generator to the overall spec

ataggart19:10:43

I assume the same goes for predicates like uuid?

ataggart20:10:06

In that we can't provide generators directly for custom predicates

Alex Miller (Clojure team)20:10:26

I think uuid? has a generator? or maybe that's just one we've talked about

Alex Miller (Clojure team)20:10:34

you can generally wrap specs with custom generators around preds with s/with-gen or s/spec

Alex Miller (Clojure team)20:10:57

the particular case of :kind in s/every is a place where you don't have that opportunity

ataggart20:10:34

I've been fighting to successfully use with-gen for about an hour now

ataggart20:10:36

And I just figured it out.

ataggart20:10:07

spec.gen wants fns for everything, but I'm used to test.check which doesn't.

ataggart20:10:33

I'm good now, thanks for your help

Alex Miller (Clojure team)20:10:41

yep, it's thunked to make the load step dynamic and optional

ataggart20:10:48

Yeah, makes sense

ataggart20:10:02

It's a one-time problem