File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -2,15 +2,12 @@ module Data.Enum.Gen where
2
2
3
3
import Prelude
4
4
5
- import Control.Monad.Gen (class MonadGen , chooseInt )
6
- import Data.Enum (class BoundedEnum , fromEnum , toEnum )
7
- import Partial.Unsafe (unsafePartial )
8
- import Data.Maybe (fromJust )
5
+ import Control.Monad.Gen (class MonadGen , elements )
6
+ import Data.Enum (class BoundedEnum , enumFromTo )
7
+ import Data.NonEmpty ((:|))
9
8
10
- -- | Create a random generator for a finite enumeration. `toEnum i` must be
11
- -- | well-behaved: it must return a `Just` value for all `Int`s between
12
- -- | `fromEnum bottom` and `fromEnum top`.
9
+ -- | Create a random generator for a finite enumeration.
13
10
genBoundedEnum :: forall m a . MonadGen m => BoundedEnum a => m a
14
11
genBoundedEnum =
15
- unsafePartial fromJust <<< toEnum
16
- <$> chooseInt (fromEnum ( bottom :: a )) (fromEnum (top :: a ) )
12
+ let possibilities = enumFromTo (bottom :: a ) (top :: a ) :: Array a
13
+ in elements ( bottom :| possibilities )
You can’t perform that action at this time.
0 commit comments