File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module Test.QuickCheck.Gen
88 , repeatable
99 , stateful
1010 , variant
11+ , suchThat
1112 , sized
1213 , resize
1314 , choose
@@ -88,6 +89,16 @@ stateful f = Gen $ state \s -> runGen (f s) s
8889variant :: forall a . Seed -> Gen a -> Gen a
8990variant n g = Gen $ state \s -> runGen g s { newSeed = n }
9091
92+ -- | Ensure that a generator only produces values that match a predicate. If
93+ -- | the predicate always returns false the generator will loop forever.
94+ suchThat :: forall a . Gen a -> (a -> Boolean ) -> Gen a
95+ suchThat gen pred = tailRecM go unit
96+ where
97+ go :: Unit -> Gen (Step Unit a )
98+ go _ = do
99+ a <- gen
100+ pure if pred a then Done a else Loop unit
101+
91102-- | Create a random generator which depends on the size parameter.
92103sized :: forall a . (Size -> Gen a ) -> Gen a
93104sized f = stateful (\s -> f s.size)
You can’t perform that action at this time.
0 commit comments