Fork me on GitHub
#test-check
<
2018-06-26
>
ghadi17:06:55

What's the most idiomatic way to make a generator from a source function (like a constructor)?

ghadi18:06:49

(gen/fmap (fn [f] (f)) (gen/return some-constructor))
Seems oblique to say fmap "apply thyself"

gfredericks18:06:05

that example might be too simple to express your problem, because you can rewrite it as (gen/return (some-constructor))

gfredericks18:06:14

unless the constructor is nondeterministic

ghadi18:06:28

I want to generate fresh instances

ghadi18:06:48

(the constructor returns a reify)

gfredericks18:06:55

is this with spec?

gfredericks18:06:06

in general it's not idiomatic in test.check to be generating non-values, so spec exposes a bit of a mismatch here

gfredericks18:06:18

but I suppose I've heard similar things from alex about spec

gfredericks18:06:19

so due to all that, there's not a more idiomatic way to do what you're doing

gfredericks18:06:49

you might even have to be careful about the same instance getting reused during shrinking

gfredericks18:06:17

I'm 87% sure that's what would happen if you compose this with other generators

ghadi18:06:33

Interesting.... Thanks Gary

gfredericks18:06:20

👍 this might be an interesting thing to point out in the spec channel