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

Headroom.Data.EnumExtra

Description

Provides extended 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.

>>> :set -XDeriveAnyClass -XTypeApplications
>>> 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.

>>> :set -XDeriveAnyClass -XTypeApplications
>>> 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.

>>> :set -XDeriveAnyClass
>>> 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.

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