Fork me on GitHub
#clojure-spec
<
2019-10-28
>
alexmiller00: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.

alexmiller16:10:09

you could wrap s/nonconforming around each pred

alexmiller16: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?)))

alexmiller16:10:51

something like that

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 [email protected])))

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.

alexmiller22:10:45

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

alexmiller22: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 ...))

alexmiller22: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.

alexmiller15: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

alexmiller20:10:26

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

alexmiller20:10:04

yeah, uuid? gens

alexmiller20:10:34

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

alexmiller20: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

alexmiller20: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