module Data.Text.Builder.Linear (
Builder (..),
runBuilder,
runBuilderBS,
fromText,
fromChar,
fromAddr,
fromDec,
fromHex,
fromDouble,
) where
import Data.Bits (FiniteBits)
import Data.ByteString.Internal (ByteString (..))
import Data.Text.Internal (Text (..))
import GHC.Exts (Addr#, IsString (..))
import Data.Text.Builder.Linear.Buffer
newtype Builder = Builder {Builder -> Buffer %1 -> Buffer
unBuilder ∷ Buffer ⊸ Buffer}
runBuilder ∷ ∀ m. Builder %m → Text
runBuilder :: forall (m :: Multiplicity). Builder %m -> Text
runBuilder (Builder Buffer %1 -> Buffer
f) = (Buffer %1 -> Buffer) %1 -> Text
runBuffer Buffer %1 -> Buffer
f
{-# INLINE runBuilder #-}
runBuilderBS ∷ ∀ m. Builder %m → ByteString
runBuilderBS :: forall (m :: Multiplicity). Builder %m -> ByteString
runBuilderBS (Builder Buffer %1 -> Buffer
f) = (Buffer %1 -> Buffer) %1 -> ByteString
runBufferBS Buffer %1 -> Buffer
f
{-# INLINE runBuilderBS #-}
instance Show Builder where
show :: Builder -> String
show (Builder Buffer %1 -> Buffer
f) = forall a. Show a => a -> String
show ((Buffer %1 -> Buffer) %1 -> Text
runBuffer Buffer %1 -> Buffer
f)
instance Semigroup Builder where
Builder Buffer %1 -> Buffer
f <> :: Builder -> Builder -> Builder
<> Builder Buffer %1 -> Buffer
g = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer %1 -> Buffer
g (Buffer %1 -> Buffer
f Buffer
b)
{-# INLINE (<>) #-}
instance Monoid Builder where
mempty :: Builder
mempty = (Buffer %1 -> Buffer) -> Builder
Builder (\Buffer
b → Buffer
b)
{-# INLINE mempty #-}
instance IsString Builder where
fromString :: String -> Builder
fromString = Text -> Builder
fromText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
{-# INLINE fromString #-}
fromText ∷ Text → Builder
fromText :: Text -> Builder
fromText Text
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b Buffer %1 -> Text -> Buffer
|> Text
x
{-# INLINE fromText #-}
fromChar ∷ Char → Builder
fromChar :: Char -> Builder
fromChar Char
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b Buffer %1 -> Char -> Buffer
|>. Char
x
{-# INLINE fromChar #-}
fromAddr ∷ Addr# → Builder
fromAddr :: Addr# -> Builder
fromAddr Addr#
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b Buffer %1 -> Addr# -> Buffer
|># Addr#
x
{-# INLINE fromAddr #-}
fromDec ∷ (Integral a, FiniteBits a) ⇒ a → Builder
fromDec :: forall a. (Integral a, FiniteBits a) => a -> Builder
fromDec a
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b forall a. (Integral a, FiniteBits a) => Buffer %1 -> a -> Buffer
|>$ a
x
{-# INLINE fromDec #-}
fromHex ∷ (Integral a, FiniteBits a) ⇒ a → Builder
fromHex :: forall a. (Integral a, FiniteBits a) => a -> Builder
fromHex a
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b forall a. (Integral a, FiniteBits a) => Buffer %1 -> a -> Buffer
|>& a
x
{-# INLINE fromHex #-}
fromDouble ∷ Double → Builder
fromDouble :: Double -> Builder
fromDouble Double
x = (Buffer %1 -> Buffer) -> Builder
Builder forall a b. (a -> b) -> a -> b
$ \Buffer
b → Buffer
b Buffer %1 -> Double -> Buffer
|>% Double
x
{-# INLINE fromDouble #-}