Skip to content
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

Add safe functions to work with 'Enum' #160

Open
chshersh opened this issue Apr 16, 2018 · 1 comment
Open

Add safe functions to work with 'Enum' #160

chshersh opened this issue Apr 16, 2018 · 1 comment
Labels
Milestone

Comments

@chshersh
Copy link
Contributor

Sometimes it's useful to have the following functions:

every      :: (Bounded a, Enum a) => [a]  -- all values
cycleSucc  :: (Bounded a, Enum a) => a -> a  -- like succ, but doesn't fail on maxBound
safeToEnum :: Enum a => Int -> Maybe a  -- Nothing if Int outside enum range

Maybe something else...

@dcastro
Copy link
Member

dcastro commented Sep 10, 2022

I would also add:

  • cyclePred
  • safeSucc :: a -> Maybe a and safePred :: a -> Maybe a

Just as safeToEnum is useful for when a is "narrower" than Int (e.g. toEnum @Word8 maxBound will throw), we should also have safeFromEnum for when a is "wider" than Int (e.g. fromEnum @Word64 maxBound will also throw)

@dcastro dcastro added this to the v.1.9.0 milestone Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants