Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class (Buildable e, Bounded e, Enum e, Eq e, Ord e, Show e, TextParsable e) => EnumText e where
- configEnumText :: e -> EnumTextConfig
- renderEnumText :: e -> Text
- buildEnumText :: e -> Builder
- parseEnumText :: Text -> Possibly e
- toFieldEnumText :: e -> ByteString
- fromFieldEnumText_ :: Monad m => ByteString -> m e
- hashWithSaltEnumText :: Int -> e -> Int
- newtype UsingEnumText a = UsingEnumText {
- _UsingEnumText :: a
- class TextParsable a where
- data EnumTextConfig = EnumTextConfig {
- _etc_text_prep :: Text -> Text
- _etc_char_prep :: Char -> Char
- defaultEnumTextConfig :: EnumTextConfig
Documentation
class (Buildable e, Bounded e, Enum e, Eq e, Ord e, Show e, TextParsable e) => EnumText e where Source #
Our toolkit for enumerated types which should be defined as follows:
import Fmt import Text.Enum.Text data Foo = FOO_bar | FOO_bar_baz deriving (Bounded,Enum,Eq,Ord,Show) instance EnumText Foo instance Buildable Foo where build = buildEnumText instance TextParsable Foo where parseText = parseEnumText
With the DeriveAnyClass
language extension you can list EnumText
in the
deriving
clause, and with DerivingVia
(available from GHC 8.6.1) you can
derive via
UsingEnumText
as follows:
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DerivingVia #-} import Fmt import Text.Enum.Text data Foo = FOO_bar | FOO_bar_baz deriving (Bounded,Enum,EnumText,Eq,Ord,Show) deriving (Buildable,TextParsable) via UsingEnumText Foo
Nothing
configEnumText :: e -> EnumTextConfig Source #
Configures the textual representation of e
generated by renderEnumText.
renderEnumText :: e -> Text Source #
Generate the standard textual representation according to
configEnumText
by default.
buildEnumText :: e -> Builder Source #
Sames as renderEnumText
, but generating a Builder
.
parseEnumText :: Text -> Possibly e Source #
Parses an e
according to the renderEnumText
render.
toFieldEnumText :: e -> ByteString Source #
A cassava field encoder, using 'the renderEnumText' format.
fromFieldEnumText_ :: Monad m => ByteString -> m e Source #
A cassava field parser using the renderEnumText
format.
hashWithSaltEnumText :: Int -> e -> Int Source #
For hashing e
with the renderEnumText
representation.
newtype UsingEnumText a Source #
Instances
EnumText a => Buildable (UsingEnumText a) Source # | |
Defined in Text.Enum.Text build :: UsingEnumText a -> Builder # | |
EnumText a => TextParsable (UsingEnumText a) Source # | |
Defined in Text.Enum.Text |
class TextParsable a where Source #
a class for Text
parsers.
Instances
TextParsable Int Source # | |
TextParsable Text Source # | |
TextParsable UTCTime Source # | |
TextParsable Day Source # | |
a ~ Char => TextParsable [a] Source # | |
TextParsable a => TextParsable (Maybe a) Source # | |
EnumText a => TextParsable (UsingEnumText a) Source # | |
Defined in Text.Enum.Text |
data EnumTextConfig Source #
Configures the default implementation of renderEnumText
EnumTextConfig | |
|
defaultEnumTextConfig :: EnumTextConfig Source #
The default configEnumText
for EnumText
:
_etc_text_prep
removes the prefix up to and including the first underscore ('_')_etc_char_prep
flips the underscores (_
) to dashes (-
)