relude-0.1.0: Custom prelude from Kowainik
Relude.Extra.Enum
universe :: (Bounded a, Enum a) => [a] Source #
Returns all values of some Bounded Enum in ascending order.
Bounded
Enum
>>> data TrafficLight = Red | Blue | Green deriving (Show, Enum, Bounded) >>> universe :: [TrafficLight] [Red,Blue,Green] >>> universe :: [Bool] [False,True]
>>>
data TrafficLight = Red | Blue | Green deriving (Show, Enum, Bounded)
universe :: [TrafficLight]
universe :: [Bool]
next :: (Eq a, Bounded a, Enum a) => a -> a Source #
Like succ, but doesn't fail on maxBound. Instead it returns minBound.
succ
maxBound
minBound
>>> next False True >>> next True False >>> succ True *** Exception: Prelude.Enum.Bool.succ: bad argument
next False
next True
succ True
safeToEnum :: forall a. (Bounded a, Enum a) => Int -> Maybe a Source #
Returns Nothing if given Int outside range.
Nothing
Int
>>> safeToEnum @Bool 0 Just False >>> safeToEnum @Bool 1 Just True >>> safeToEnum @Bool 2 Nothing >>> safeToEnum @Bool (-1) Nothing
safeToEnum @Bool 0
safeToEnum @Bool 1
safeToEnum @Bool 2
safeToEnum @Bool (-1)