relude-0.1.0: Custom prelude from Kowainik

Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.Enum

Synopsis

Documentation

universe :: (Bounded a, Enum a) => [a] Source #

Returns all values of some Bounded Enum in ascending order.

>>> data TrafficLight = Red | Blue | Green deriving (Show, Enum, Bounded)
>>> universe :: [TrafficLight]
[Red,Blue,Green]
>>> universe :: [Bool]
[False,True]

next :: (Eq a, Bounded a, Enum a) => a -> a Source #

Like succ, but doesn't fail on maxBound. Instead it returns minBound.

>>> next False
True
>>> next True
False
>>> succ True
*** Exception: Prelude.Enum.Bool.succ: bad argument

safeToEnum :: forall a. (Bounded a, Enum a) => Int -> Maybe a Source #

Returns Nothing if given Int outside range.

>>> safeToEnum @Bool 0
Just False
>>> safeToEnum @Bool 1
Just True
>>> safeToEnum @Bool 2
Nothing
>>> safeToEnum @Bool (-1)
Nothing