We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
genBoundedEnum
1 parent bf99e6a commit d307db5Copy full SHA for d307db5
src/Data/Enum/Gen.purs
@@ -0,0 +1,18 @@
1
+module Data.Enum.Gen where
2
+
3
+import Prelude
4
5
+import Control.Monad.Gen (class MonadGen, elements)
6
+import Data.Enum (class BoundedEnum, succ, enumFromTo)
7
+import Data.Maybe (Maybe(..))
8
+import Data.NonEmpty ((:|))
9
10
+-- | Create a random generator for a finite enumeration.
11
+genBoundedEnum :: forall m a. MonadGen m => BoundedEnum a => m a
12
+genBoundedEnum =
13
+ case succ bottom of
14
+ Just a →
15
+ let possibilities = enumFromTo a top :: Array a
16
+ in elements (bottom :| possibilities)
17
+ Nothing →
18
+ pure bottom
0 commit comments