Generates a value that satisfies a predicate.
Shrinks of the generated value will also satisfy the predicate. From
the original generator's shrink tree, any values that fail the
predicate will be removed, along with their subsequent shrinks.
Compared to
filter, shrinking may be faster but may also be
less optimal.
The type is also more general, because the shrink behavior from
filter would force the entire shrink tree to be evaluated when
applied to an impure tree.
This is essentially:
filterT p gen = mfilter p gen <|> filterT p gen
But that could loop forever, if the predicate will never pass or will
only pass at a larger size than we're currently running at. We differ
from the above in keeping some state to avoid that. We limit the
number of retries, and grow the size with each retry. If we retry too
many times then the whole generator is discarded.