quickcheck icon indicating copy to clipboard operation
quickcheck copied to clipboard

introduce `discardUnless`

Open MaximilianAlgehed opened this issue 11 months ago • 4 comments

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.

MaximilianAlgehed avatar Mar 21 '24 12:03 MaximilianAlgehed

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.

nick8325 avatar Mar 23 '24 17:03 nick8325

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.

MaximilianAlgehed avatar Mar 23 '24 20:03 MaximilianAlgehed

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.

MaximilianAlgehed avatar Mar 24 '24 07:03 MaximilianAlgehed

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.

nick8325 avatar Apr 25 '24 12:04 nick8325