| Copyright | (c) 2022 Andrew Lelechenko |
|---|---|
| License | BSD3 |
| Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
| Safe Haskell | None |
| Language | GHC2021 |
Data.Text.Builder.Linear
Description
Builder for strict Text and ByteString, based on linear types. It consistently
outperforms Data.Text.Lazy.Builder
from text as well as a strict builder from text-builder,
and scales better.
Synopsis
- newtype Builder = Builder {}
- runBuilder :: forall (m :: Multiplicity). Builder %m -> Text
- runBuilderBS :: forall (m :: Multiplicity). Builder %m -> ByteString
- fromText :: Text -> Builder
- fromChar :: Char -> Builder
- fromAddr :: Addr# -> Builder
- fromDec :: (Integral a, FiniteBits a) => a -> Builder
- fromHex :: (Integral a, FiniteBits a) => a -> Builder
- fromDouble :: Double -> Builder
Documentation
Thin wrapper over Buffer with a handy Semigroup instance.
>>>:set -XOverloadedStrings -XMagicHash>>>fromText "foo" <> fromChar '_' <> fromAddr "bar"#"foo_bar"
Remember: this is a strict builder, so on contrary to Data.Text.Lazy.Builder for optimal performance you should use strict left folds instead of lazy right ones.
Note that (similar to other builders) concatenation of Builders allocates
thunks. This is to a certain extent mitigated by aggressive inlining,
but it is faster to use Buffer directly.
runBuilder :: forall (m :: Multiplicity). Builder %m -> Text #
runBuilderBS :: forall (m :: Multiplicity). Builder %m -> ByteString #
Same as runBuilder, but returning a UTF-8 encoded strict ByteString.
fromDec :: (Integral a, FiniteBits a) => a -> Builder #
Create Builder, containing decimal representation of a given integer.
>>>fromChar 'x' <> fromDec (123 :: Int)"x123"