relude-0.1.1: Custom prelude from Kowainik

Safe HaskellSafe
LanguageHaskell2010

Relude.String.Conversion

Contents

Description

This module implements type class which allow to have conversion to and from Text, String and ByteString types (including both strict and lazy versions). Usually you need to export Text modules qualified and use pack / unpack functions to convert to/from Text. Now you can just use toText / toString functions.

Synopsis

Convenient type aliases

type LText = Text Source #

Type synonym for Text.

type LByteString = ByteString Source #

Type synonym for ByteString.

Conversion type classes

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\1072\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
Instances
ConvertUtf8 String ByteString Source # 
Instance details

Defined in Relude.String.Conversion

ConvertUtf8 String ByteString Source # 
Instance details

Defined in Relude.String.Conversion

ConvertUtf8 Text ByteString Source # 
Instance details

Defined in Relude.String.Conversion

ConvertUtf8 Text ByteString Source # 
Instance details

Defined in Relude.String.Conversion

ConvertUtf8 Text ByteString Source # 
Instance details

Defined in Relude.String.Conversion

ConvertUtf8 Text ByteString Source # 
Instance details

Defined in Relude.String.Conversion

class ToString a where Source #

Type class for converting other strings to String.

Minimal complete definition

toString

Methods

toString :: a -> String Source #

Instances
ToString String Source # 
Instance details

Defined in Relude.String.Conversion

ToString Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toString :: Text -> String Source #

ToString Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toString :: Text -> String Source #

class ToLText a where Source #

Type class for converting other strings to Text.

Minimal complete definition

toLText

Methods

toLText :: a -> Text Source #

Instances
ToLText String Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toLText :: String -> Text Source #

ToLText Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toLText :: Text -> Text Source #

ToLText Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toLText :: Text -> Text0 Source #

class ToText a where Source #

Type class for converting other strings to Text.

Minimal complete definition

toText

Methods

toText :: a -> Text Source #

Instances
ToText String Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toText :: String -> Text Source #

ToText Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toText :: Text -> Text0 Source #

ToText Text Source # 
Instance details

Defined in Relude.String.Conversion

Methods

toText :: Text -> Text Source #

class LazyStrict l s | l -> s, s -> l where Source #

Type class for lazy-strict conversions.

Minimal complete definition

toLazy, toStrict

Methods

toLazy :: s -> l Source #

toStrict :: l -> s Source #

fromLazy :: LazyStrict l s => l -> s Source #

fromStrict :: LazyStrict l s => s -> l Source #

Show and read functions

readEither :: (ToString a, Read b) => a -> Either Text b Source #

Polymorhpic version of readEither.

>>> readEither @Text @Int "123"
Right 123
>>> readEither @Text @Int "aa"
Left "Prelude.read: no parse"

show :: forall b a. (Show a, IsString b) => a -> b Source #

Generalized version of show.