Copyright | (c) 2019-2021 Vaclav Svejcar |
---|---|
License | BSD-3-Clause |
Maintainer | vaclav.svejcar@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Provides extra functionality for enum-like types, e.g. reading/writing from/to textual representation, etc.
Synopsis
- class (Bounded a, Enum a, Eq a, Ord a, Show a) => EnumExtra a where
- allValues :: [a]
- allValuesToText :: Text
- enumToText :: a -> Text
- textToEnum :: Text -> Maybe a
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.
Nothing
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
Instances
EnumExtra FileType Source # | |
Defined in Headroom.FileType.Types | |
EnumExtra LicenseType Source # | |
Defined in Headroom.Configuration.Types allValues :: [LicenseType] Source # allValuesToText :: Text Source # enumToText :: LicenseType -> Text Source # textToEnum :: Text -> Maybe LicenseType Source # |