relude-1.2.1.0: Safe, performant, user-friendly and lightweight Haskell Standard Library
Copyright(c) 2018-2023 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellSafe
LanguageHaskell2010

Relude.Extra.Enum

Description

Mini bounded-enum framework inside relude.

Since: 0.1.0

Synopsis

Documentation

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

Since: 0.1.0

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

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

>>> prev True
False
>>> prev False
True
>>> pred False
*** Exception: Prelude.Enum.Bool.pred: bad argument

Since: 0.6.0.0

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

Since: 0.1.0