quickcheck
quickcheck copied to clipboard
introduce `discardUnless`
Closes #363
The tricky thing here is the lazy behaviour of Gen
and forAll
. That's what makes me unsure whether or not suchThatDiscard
is a good idea in practice.
What's the use case for this?
It's unfortunate that this has a similar name to suchThat
and suchThatMaybe
but behaves rather differently - in that it only tries the generator once but they retry until they succeed.
I should clarify. I don't feel particularly strongly about this idea (and the name does suck, perhaps discardUnless
would be better?) but I was hoping it might provide a nicer interface to discard for #363 but that's just an idea.
I'll clarify some more. The problem raised by the issue is basically that unless (p a) discard >> pure a
is a pitfall. Its clear what you intend but that is not what you get. By introducing a suchThat
like thing you can express this intention in a natural way that does what you want.
We can have a separate conversation about what the role of discard
is and whether or not its a good idea to use it in Gen
but the problem raised by the issue is that since its there people are using it.
I must admit, I'm a bit sceptical that people will actually use this, just because I always find the suchThat
API a bit clunky to use. But I've no objection to merging it.