headroom-0.4.3.0: License Header Manager
Copyright(c) 2019-2022 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Headroom.Data.EnumExtra

Description

Provides extra functionality for enum-like types, e.g. reading/writing from/to textual representation, etc.

Synopsis

Documentation

class (Bounded a, Enum a, Eq a, Ord a, Show a) => EnumExtra a where Source #

Enum data type, capable to (de)serialize itself from/to string representation. Can be automatically derived by GHC using the DeriveAnyClass extension.

Minimal complete definition

Nothing

Methods

allValues :: [a] Source #

Returns list of all enum values.

>>> data Test = Foo | Bar deriving (Bounded, Enum, EnumExtra, Eq, Ord, Show)
>>> allValues @Test
[Foo,Bar]

allValuesToText :: Text Source #

Returns all values of enum as single string, individual values separated with comma.

>>> data Test = Foo | Bar deriving (Bounded, Enum, EnumExtra, Eq, Ord, Show)
>>> allValuesToText @Test
"Foo, Bar"

enumToText :: a -> Text Source #

Returns textual representation of enum value. Opposite to textToEnum.

>>> data Test = Foo | Bar deriving (Bounded, Enum, EnumExtra, Eq, Ord, Show)
>>> enumToText Bar
"Bar"

textToEnum :: Text -> Maybe a Source #

Returns enum value from its textual representation. Opposite to enumToText.

>>> data Test = Foo | Bar deriving (Bounded, Enum, EnumExtra, Eq, Ord, Show)
>>> (textToEnum "Foo") :: (Maybe Test)
Just Foo