-
Notifications
You must be signed in to change notification settings - Fork 24
Add genBoundedEnum
#29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Data/Enum/Gen.purs
Outdated
-- | `fromEnum bottom` and `fromEnum top`. | ||
genBoundedEnum :: forall m a. MonadGen m => BoundedEnum a => m a | ||
genBoundedEnum = | ||
unsafePartial fromJust <<< toEnum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unsafePartial
is only safe if the Enum
instance is valid, I think.
Another option is oneOf (bottom .. top)
, or something along those lines, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generator I lifted from QuickCheck actually, it was recently added there, so it suffers from any of the same problems that that one has.
Can you explain what you're thinking with oneOf (bottom .. top)
, I'm not sure I follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does say in the comment that toEnum
must be well behaved too 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By bottom .. top
, I meant to say enumFromTo
bottom top
, which must be safe, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah, that'd work. It'll be kinda expensive if used for large enums, but can revisit if we have a case where it's obviously terrible. :)
How's this? A slight bias to |
👍 Thanks! |
No description provided.