text-class-2022.7.1: Extra helpers to convert data-types to and from Text
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Data.Text.Class

Description

Extend the Text module with an extra abstraction to encode and decode values safely to and from Text . It's very similar to FromJSON and ToJSON from Aeson .

Synopsis

Producing and consuming text from arbitrary types

fromTextMaybe :: FromText a => Text -> Maybe a Source #

Decode the specified text with a Maybe result type.

Producing and consuming text from bounded enumeration types

data CaseStyle Source #

Represents a case style for multi-word strings.

Constructors

CamelCase

A string in the style of "doNotRepeatYourself"

PascalCase

A string in the style of DoNotRepeatYourself

KebabLowerCase

A string in the style of "do-not-repeat-yourself"

SnakeLowerCase

A string in the style of "do_not_repeat_yourself"

SnakeUpperCase

A string in the style of DO_NOT_REPEAT_YOURSELF

SpacedLowerCase

A string in the style of "do not repeat yourself"

Instances

Instances details
Bounded CaseStyle Source #
Instance details

Defined in Data.Text.Class

Enum CaseStyle Source #
Instance details

Defined in Data.Text.Class

Eq CaseStyle Source #
Instance details

Defined in Data.Text.Class

Show CaseStyle Source #
Instance details

Defined in Data.Text.Class

Generic CaseStyle Source #
Instance details

Defined in Data.Text.Class

type Rep CaseStyle Source #
Instance details

Defined in Data.Text.Class

type Rep CaseStyle = D1 (' MetaData "CaseStyle" "Data.Text.Class" "text-class-2022.7.1-H44fwxTdr9DK1tRODTWq6U" ' False ) (( C1 (' MetaCons "CamelCase" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: ( C1 (' MetaCons "PascalCase" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "KebabLowerCase" ' PrefixI ' False ) ( U1 :: Type -> Type ))) :+: ( C1 (' MetaCons "SnakeLowerCase" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: ( C1 (' MetaCons "SnakeUpperCase" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "SpacedLowerCase" ' PrefixI ' False ) ( U1 :: Type -> Type ))))

toTextFromBoundedEnum :: forall a. ( Bounded a, Enum a, Show a) => CaseStyle -> a -> Text Source #

Converts the given value to text, according to the specified CaseStyle .

This function guarantees to satisfy the following property:

fromTextToBoundedEnum s (toTextFromBoundedEnum s a) == Right a

fromTextToBoundedEnum :: forall a. ( Bounded a, Enum a, Show a) => CaseStyle -> Text -> Either TextDecodingError a Source #

Parses the given text to a value, according to the specified CaseStyle .

This function guarantees to satisfy the following property:

fromTextToBoundedEnum s (toTextFromBoundedEnum s a) == Right a

Helpers

showT :: ToText a => a -> String Source #

Show a data-type through its ToText instance