blaze-builder-0.1: Builder to efficiently append text.

Text.Blaze.Builder.Core

Contents

Description

The builder monoid from BlazeHtml.

Usage is fairly straightforward. Builders can be constructed from many values, including String and Text values.

 strings :: [String]
 strings = replicate 10000 "Hello there!"

Concatenation should happen through the Monoid interface.

 concatenation :: Builder
 concatenation = mconcat $ map fromString strings

There is only one way to efficiently obtain the result: to convert the Builder to a lazy ByteString using toLazyByteString.

 result :: L.ByteString
 result = toLazyByteString concatenation

Synopsis

Main builder type

data Builder Source

Main builder type. It simply contains a function to extract the actual data.

Instances

Custom writes to the builder

data Write Source

Write abstraction so we can avoid some gory and bloody details. A write abstration holds the exact size of the write in bytes, and a function to carry out the write operation.

Constructors

Write !Int (Ptr Word8 -> IO ()) 

Instances

writeByteSource

Arguments

:: Word8

Byte to write

-> Write

Resulting write

Write a single byte.

writeByteStringSource

Arguments

:: ByteString

ByteString to write

-> Write

Resulting write

Write a strict ByteString.

writeSingletonSource

Arguments

:: (a -> Write)

Write abstraction

-> a

Actual value to write

-> Builder

Resulting Builder

Construct a Builder from a single Write abstraction.

writeListSource

Arguments

:: (a -> Write)

Write abstraction

-> [a]

List of values to write

-> Builder

Resulting Builder

Construct a builder writing a list of data from a write abstraction.

Creating builders

singletonSource

Arguments

:: Word8

Byte to create a Builder from

-> Builder

Resulting Builder

Construct a Builder from a single byte.

fromByteStringSource

Arguments

:: ByteString

Strict ByteString to copy

-> Builder

Resulting Builder

O(n). A Builder taking a ByteString, copying it.

Extracting the result from a builder

toLazyByteStringSource

Arguments

:: Builder

Builder to evaluate

-> ByteString

Resulting UTF-8 encoded ByteString

O(n). Extract the lazy ByteString from the builder.