universum-0.7.0: Custom prelude used in Serokell

Safe HaskellSafe
LanguageHaskell2010

Conv

Description

Type classes for convertion between different string representations.

Synopsis

Documentation

class ConvertUtf8 a b where Source #

Type class for conversion to utf8 representation of text.

Minimal complete definition

encodeUtf8, decodeUtf8, decodeUtf8Strict

Methods

encodeUtf8 :: a -> b Source #

Encode as utf8 string (usually ByteString).

>>> encodeUtf8 @Text @ByteString "патак"
"\208\191\208\176\209\130\208\176\208\186"

decodeUtf8 :: b -> a Source #

Decode from utf8 string.

>>> decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186"
"\1087\1072\1090\1072\1082"
>>> putStrLn $ decodeUtf8 @Text @ByteString "\208\191\208\176\209\130\208\176\208\186"
патак

decodeUtf8Strict :: b -> Either UnicodeException a Source #

Decode as utf8 string but returning execption if byte sequence is malformed.

>>> decodeUtf8 @Text @ByteString "\208\208\176\209\130\208\176\208\186"
"\65533\65533\1090\1072\1082"
>>> decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"
Left Cannot decode byte '\xd0': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream

class ToString a where Source #

Type class for converting other strings to String.

Minimal complete definition

toString

Methods

toString :: a -> String Source #

class ToLText a where Source #

Type class for converting other strings to Text.

Minimal complete definition

toLText

Methods

toLText :: a -> Text Source #

class ToText a where Source #

Type class for converting other strings to Text.

Minimal complete definition

toText

Methods

toText :: a -> Text Source #