Z-Data-0.1.0.0: array, vector and text
Copyright(c) Dong Han 2017-2019
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.Data.Text.Builder

Description

Base on UTF8 compatible textual builders from Builder, we provide a newtype wrapper TextBuilder which can be directly used to build Text.

We also provide faster alternative to Show class, i.e. ToText, which also provides Generic based instances deriving.

Synopsis

ToText class

class ToText a where Source #

A class similar to Show, serving the purpose that quickly convert a data type to a Text value.

Minimal complete definition

Nothing

Methods

toTextBuilder :: Int -> a -> TextBuilder () Source #

default toTextBuilder :: (Generic a, GToText (Rep a)) => Int -> a -> TextBuilder () Source #

Instances

Instances details
ToText Bool Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Char Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Double Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Float Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Int Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Int8 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Int16 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Int32 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Int64 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Integer Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Natural Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Ordering Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Word Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Word8 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Word16 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Word32 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Word64 Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText () Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> () -> TextBuilder () Source #

ToText Version Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText Text Source #

To keep sync with Show instance's escaping rule, we reuse show here, so it won't be as fast as memcpy.

Instance details

Defined in Z.Data.Text.Builder

ToText Scientific Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Scientific -> TextBuilder () Source #

ToText Str Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText FlatIntSet Source # 
Instance details

Defined in Z.Data.Vector.FlatIntSet

ToText Value Source # 
Instance details

Defined in Z.Data.JSON.Value

ToText a => ToText [a] Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> [a] -> TextBuilder () Source #

ToText a => ToText (Maybe a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Maybe a -> TextBuilder () Source #

(ToText a, Integral a) => ToText (Ratio a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Ratio a -> TextBuilder () Source #

ToText a => ToText (Min a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Min a -> TextBuilder () Source #

ToText a => ToText (Max a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Max a -> TextBuilder () Source #

ToText a => ToText (First a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> First a -> TextBuilder () Source #

ToText a => ToText (Last a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Last a -> TextBuilder () Source #

ToText a => ToText (WrappedMonoid a) Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText a => ToText (Identity a) Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText a => ToText (First a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> First a -> TextBuilder () Source #

ToText a => ToText (Last a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Last a -> TextBuilder () Source #

ToText a => ToText (Dual a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Dual a -> TextBuilder () Source #

ToText a => ToText (NonEmpty a) Source # 
Instance details

Defined in Z.Data.Text.Builder

(Prim a, ToText a) => ToText (PrimVector a) Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText a => ToText (Vector a) Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText (TextBuilder a) Source # 
Instance details

Defined in Z.Data.Text.Builder

ToText v => ToText (FlatSet v) Source # 
Instance details

Defined in Z.Data.Vector.FlatSet

ToText v => ToText (FlatIntMap v) Source # 
Instance details

Defined in Z.Data.Vector.FlatIntMap

(ToText a, ToText b) => ToText (Either a b) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Either a b -> TextBuilder () Source #

(ToText a, ToText b) => ToText (a, b) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b) -> TextBuilder () Source #

HasResolution a => ToText (Fixed a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Fixed a -> TextBuilder () Source #

ToText (Proxy a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Proxy a -> TextBuilder () Source #

(ToText k, ToText v) => ToText (FlatMap k v) Source # 
Instance details

Defined in Z.Data.Vector.FlatMap

Methods

toTextBuilder :: Int -> FlatMap k v -> TextBuilder () Source #

(ToText a, ToText b, ToText c) => ToText (a, b, c) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b, c) -> TextBuilder () Source #

ToText a => ToText (Const a b) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Const a b -> TextBuilder () Source #

ToText b => ToText (Tagged a b) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Tagged a b -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d) => ToText (a, b, c, d) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b, c, d) -> TextBuilder () Source #

(ToText (f a), ToText (g a)) => ToText (Product f g a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Product f g a -> TextBuilder () Source #

(ToText (f a), ToText (g a), ToText a) => ToText (Sum f g a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Sum f g a -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e) => ToText (a, b, c, d, e) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b, c, d, e) -> TextBuilder () Source #

ToText (f (g a)) => ToText (Compose f g a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> Compose f g a -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e, ToText f) => ToText (a, b, c, d, e, f) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b, c, d, e, f) -> TextBuilder () Source #

(ToText a, ToText b, ToText c, ToText d, ToText e, ToText f, ToText g) => ToText (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

toTextBuilder :: Int -> (a, b, c, d, e, f, g) -> TextBuilder () Source #

toText :: ToText a => a -> Text Source #

Directly convert data to Text.

toBuilder :: ToText a => a -> Builder () Source #

Directly convert data to Builder.

toBytes :: ToText a => a -> Bytes Source #

Directly convert data to Bytes.

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

Faster show replacement.

Str newtype

newtype Str Source #

Newtype wrapper for [Char] to provide textual instances.

To encourage using Text as the textual representation, we didn't provide special treatment to differentiate instances between [a] and [Char] in various places. This newtype is therefore to provide instances similar to T.Text, in case you really need to wrap a String.

Constructors

Str 

Fields

Instances

Instances details
Eq Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

(==) :: Str -> Str -> Bool #

(/=) :: Str -> Str -> Bool #

Data Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Str -> c Str #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Str #

toConstr :: Str -> Constr #

dataTypeOf :: Str -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Str) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Str) #

gmapT :: (forall b. Data b => b -> b) -> Str -> Str #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Str -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Str -> r #

gmapQ :: (forall d. Data d => d -> u) -> Str -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Str -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Str -> m Str #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Str -> m Str #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Str -> m Str #

Ord Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

compare :: Str -> Str -> Ordering #

(<) :: Str -> Str -> Bool #

(<=) :: Str -> Str -> Bool #

(>) :: Str -> Str -> Bool #

(>=) :: Str -> Str -> Bool #

max :: Str -> Str -> Str #

min :: Str -> Str -> Str #

Read Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Show Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

showsPrec :: Int -> Str -> ShowS #

show :: Str -> String #

showList :: [Str] -> ShowS #

Generic Str Source # 
Instance details

Defined in Z.Data.Text.Builder

Associated Types

type Rep Str :: Type -> Type #

Methods

from :: Str -> Rep Str x #

to :: Rep Str x -> Str #

ToText Str Source # 
Instance details

Defined in Z.Data.Text.Builder

FromValue Str Source # 
Instance details

Defined in Z.Data.JSON.Base

EncodeJSON Str Source # 
Instance details

Defined in Z.Data.JSON.Base

Methods

encodeJSON :: Str -> Builder () Source #

ToValue Str Source # 
Instance details

Defined in Z.Data.JSON.Base

Methods

toValue :: Str -> Value Source #

type Rep Str Source # 
Instance details

Defined in Z.Data.Text.Builder

type Rep Str = D1 ('MetaData "Str" "Z.Data.Text.Builder" "Z-Data-0.1.0.0-inplace" 'True) (C1 ('MetaCons "Str" 'PrefixI 'True) (S1 ('MetaSel ('Just "chrs") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Char])))

Textual Builder

data TextBuilder a Source #

Buidlers which guarantee UTF-8 encoding, thus can be used to build text directly.

Notes on IsString instance: It's recommended to use IsString instance, there's a rewrite rule to turn encoding loop into a memcpy, which is much faster (the same rule also apply to stringUTF8). Different from Builder (), TextBuilder ()'s IsString instance will give you desired UTF8 guarantees:

  • NUL will be written directly as x00.
  • xD800 ~ xDFFF will be replaced by replacement char.

Instances

Instances details
Monad TextBuilder Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

(>>=) :: TextBuilder a -> (a -> TextBuilder b) -> TextBuilder b #

(>>) :: TextBuilder a -> TextBuilder b -> TextBuilder b #

return :: a -> TextBuilder a #

Functor TextBuilder Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

fmap :: (a -> b) -> TextBuilder a -> TextBuilder b #

(<$) :: a -> TextBuilder b -> TextBuilder a #

Applicative TextBuilder Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

pure :: a -> TextBuilder a #

(<*>) :: TextBuilder (a -> b) -> TextBuilder a -> TextBuilder b #

liftA2 :: (a -> b -> c) -> TextBuilder a -> TextBuilder b -> TextBuilder c #

(*>) :: TextBuilder a -> TextBuilder b -> TextBuilder b #

(<*) :: TextBuilder a -> TextBuilder b -> TextBuilder a #

Show (TextBuilder a) Source # 
Instance details

Defined in Z.Data.Text.Builder

a ~ () => IsString (TextBuilder a) Source # 
Instance details

Defined in Z.Data.Text.Builder

Semigroup (TextBuilder ()) Source # 
Instance details

Defined in Z.Data.Text.Builder

Monoid (TextBuilder ()) Source # 
Instance details

Defined in Z.Data.Text.Builder

Arbitrary (TextBuilder ()) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

arbitrary :: Gen (TextBuilder ())

shrink :: TextBuilder () -> [TextBuilder ()]

CoArbitrary (TextBuilder ()) Source # 
Instance details

Defined in Z.Data.Text.Builder

Methods

coarbitrary :: TextBuilder () -> Gen b -> Gen b

ToText (TextBuilder a) Source # 
Instance details

Defined in Z.Data.Text.Builder

unsafeFromBuilder :: Builder a -> TextBuilder a Source #

Unsafely turn a Builder into TextBuilder, thus it's user's responsibility to ensure only UTF-8 complied bytes are written.

buildText :: TextBuilder a -> Text Source #

Build a Text using TextBuilder, which provide UTF-8 encoding guarantee.

Basic UTF8 builders

stringUTF8 :: String -> TextBuilder () Source #

Turn String into TextBuilder with UTF8 encoding

Illegal codepoints will be written as replacementChars. This function will be rewritten into a memcpy if possible, (running a fast UTF-8 validation at runtime first).

charUTF8 :: Char -> TextBuilder () Source #

Turn Char into TextBuilder with UTF8 encoding

Illegal codepoints will be written as replacementChars.

string7 :: String -> TextBuilder () Source #

Turn String into TextBuilder with ASCII7 encoding

Codepoints beyond 'x7F' will be chopped.

char7 :: Char -> TextBuilder () Source #

Turn Char into TextBuilder with ASCII7 encoding

Codepoints beyond 'x7F' will be chopped.

text :: Text -> TextBuilder () Source #

Write UTF8 encoded Text using Builder.

Note, if you're trying to write string literals builders, please open OverloadedStrings and use Builders IsString instance, it will be rewritten into a memcpy.

Numeric builders

Integral type formatting

data IFormat Source #

Integral formatting options.

Constructors

IFormat 

Fields

Instances

Instances details
Eq IFormat Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

(==) :: IFormat -> IFormat -> Bool #

(/=) :: IFormat -> IFormat -> Bool #

Ord IFormat Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Show IFormat Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Arbitrary IFormat Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

arbitrary :: Gen IFormat

shrink :: IFormat -> [IFormat]

CoArbitrary IFormat Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

coarbitrary :: IFormat -> Gen b -> Gen b

defaultIFormat :: IFormat Source #

defaultIFormat = IFormat 0 NoPadding False

data Padding Source #

Instances

Instances details
Enum Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Eq Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

(==) :: Padding -> Padding -> Bool #

(/=) :: Padding -> Padding -> Bool #

Ord Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Show Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Arbitrary Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

arbitrary :: Gen Padding

shrink :: Padding -> [Padding]

CoArbitrary Padding Source # 
Instance details

Defined in Z.Data.Builder.Numeric

Methods

coarbitrary :: Padding -> Gen b -> Gen b

int :: (Integral a, Bounded a) => a -> TextBuilder () Source #

int = intWith defaultIFormat

intWith :: (Integral a, Bounded a) => IFormat -> a -> TextBuilder () Source #

Format a Bounded Integral type like Int or Word16 into decimal ascii digits.

integer :: Integer -> TextBuilder () Source #

Format a Integer into decimal ascii digits.

Fixded size hexidecimal formatting

hex :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #

Format a FiniteBits Integral type into hex nibbles.

heX :: (FiniteBits a, Integral a) => a -> TextBuilder () Source #

The UPPERCASED version of hex.

IEEE float formating

data FFormat Source #

Control the rendering of floating point numbers.

Constructors

Exponent

Scientific notation (e.g. 2.3e123).

Fixed

Standard decimal notation.

Generic

Use decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

double :: Double -> TextBuilder () Source #

Decimal encoding of an IEEE Double.

Using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

doubleWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Double 
-> TextBuilder () 

Format double-precision float using drisu3 with dragon4 fallback.

float :: Float -> TextBuilder () Source #

Decimal encoding of an IEEE Float.

Using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

floatWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Float 
-> TextBuilder () 

Format single-precision float using drisu3 with dragon4 fallback.

scientific :: Scientific -> TextBuilder () Source #

A Builder which renders a scientific number to full precision, using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

scientificWith Source #

Arguments

:: FFormat 
-> Maybe Int

Number of decimal places to render.

-> Scientific 
-> TextBuilder () 

Like scientific but provides rendering options.

Builder helpers

paren :: TextBuilder () -> TextBuilder () Source #

add (...) to original builder.

parenWhen :: Bool -> TextBuilder () -> TextBuilder () Source #

Add "(..)" around builders when condition is met, otherwise add nothing.

This is useful when defining ToText instances.

curly :: TextBuilder () -> TextBuilder () Source #

add {...} to original builder.

square :: TextBuilder () -> TextBuilder () Source #

add [...] to original builder.

angle :: TextBuilder () -> TextBuilder () Source #

add ... to original builder.

quotes :: TextBuilder () -> TextBuilder () Source #

add "..." to original builder.

squotes :: TextBuilder () -> TextBuilder () Source #

add ... to original builder.

colon :: TextBuilder () Source #

write an ASCII :

comma :: TextBuilder () Source #

write an ASCII ,

intercalateVec Source #

Arguments

:: Vec v a 
=> TextBuilder ()

the seperator

-> (a -> TextBuilder ())

value formatter

-> v a

value list

-> TextBuilder () 

Use separator to connect a vector of builders.

intercalateList Source #

Arguments

:: TextBuilder ()

the seperator

-> (a -> TextBuilder ())

value formatter

-> [a]

value vector

-> TextBuilder () 

Use separator to connect a list of builders.