| Portability | portable to Hugs and GHC |
|---|---|
| Stability | experimental |
| Maintainer | Johan Tibell <johan.tibell@gmail.com> |
| Safe Haskell | None |
Data.Text.Lazy.Builder
Description
Efficient construction of lazy Text values. The principal
operations on a Builder are singleton, fromText, and
fromLazyText, which construct new builders, and mappend, which
concatenates two builders.
To get maximum performance when building lazy Text values using a
builder, associate mappend calls to the right. For example,
prefer
singleton 'a' `mappend` (singleton 'b' `mappend` singleton 'c')
to
singleton 'a' `mappend` singleton 'b' `mappend` singleton 'c'
as the latter associates mappend to the left.
The Builder type
A Builder is an efficient way to build lazy Text values.
There are several functions for constructing builders, but only one
to inspect them: to extract any data, you have to turn them into
lazy Text values using toLazyText.
Internally, a builder constructs a lazy Text by filling arrays
piece by piece. As each buffer is filled, it is 'popped' off, to
become a new chunk of the resulting lazy Text. All this is
hidden from the user of the Builder.
toLazyText :: Builder -> TextSource
O(n). Extract a lazy Text from a Builder with a default
buffer size. The construction work takes place if and when the
relevant part of the lazy Text is demanded.
toLazyTextWith :: Int -> Builder -> TextSource
O(n). Extract a lazy Text from a Builder, using the given
size for the initial buffer. The construction work takes place if
and when the relevant part of the lazy Text is demanded.
If the initial buffer is too small to hold all data, subsequent buffers will be the default buffer size.
Constructing Builders
singleton :: Char -> BuilderSource
O(1). A Builder taking a single character, satisfying
toLazyText(singletonc) =singletonc
fromText :: Text -> BuilderSource
O(1). A Builder taking a Text, satisfying
toLazyText(fromTextt) =fromChunks[t]
fromLazyText :: Text -> BuilderSource
O(1). A Builder taking a lazy Text, satisfying
toLazyText(fromLazyTextt) = t
fromString :: String -> BuilderSource
O(1). A Builder taking a String, satisfying
toLazyText(fromStrings) =fromChunks[S.pack s]