You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
toEnum is partial. If the type is not only Enum but also Bounded it's simple enough to implement a non-partial version, e.g.
toEnumSafe::foralla. (Enuma, Boundeda) =>Int->Maybea
toEnumSafe i = guard (inBounds i) $>toEnum i where
inBounds = inRange $ join bimap (fromEnum@a) (minBound, maxBound)
{-# INLINE toEnumSafe #-} -- the hope is most of 'inBounds' can be evalueated at compile time if 'a' is known
(inRange is defined in Data.Ix)
There are versions of this in relude and safe. It's occasionally very useful.
The text was updated successfully, but these errors were encountered:
toEnum
is partial. If the type is not onlyEnum
but alsoBounded
it's simple enough to implement a non-partial version, e.g.(
inRange
is defined inData.Ix
)There are versions of this in
relude
andsafe
. It's occasionally very useful.The text was updated successfully, but these errors were encountered: