Strict vs lazy types

This package provides both strict and lazy Text types. The
strict type is provided by the Data.Text package, while the lazy
type is provided by the Data.Text.Lazy package. Internally, the
lazy Text type consists of a list of strict chunks.

The strict Text type requires that an entire string fit into
memory at once. The lazy Text type is capable of streaming
strings that are larger than memory using a small memory footprint.
In many cases, the overhead of chunked streaming makes the lazy
Text type slower than its strict counterpart, but this is not
always the case. Sometimes, the time complexity of a function in
one module may be different from the other, due to their differing
internal structures.

Each module provides an almost identical API, with the main
difference being that the strict module uses Int values for
lengths and counts, while the lazy module uses Int64 lengths.

Fusion

Most of the functions in this module are subject to fusion,
meaning that a pipeline of such functions will usually allocate at
most one Text value.

From the type signatures involved, this looks like it should
allocate one ByteString value, and two Text values. However,
when a module is compiled with optimisation enabled under GHC, the
two intermediate Text values will be optimised away, and the
function will be compiled down to a single loop over the source
ByteString.

Functions that can be fused by the compiler are marked with the
phrase "Subject to fusion".

Case conversion

When case converting Text values, do not use combinators like
map toUpper to case convert each character of a string
individually, as this gives incorrect results according to the
rules of some writing systems. The whole-string case conversion
functions from this module, such as toUpper, obey the correct
case conversion rules. As a result, these functions may map one
input character to two or three output characters. For examples,
see the documentation of each function.

Note: In some languages, case conversion is a locale- and
context-dependent operation. The case conversion functions in this
module are not locale sensitive. Programs that require locale
sensitivity should use appropriate versions of the case mapping
functions from the text-icu package.

O(n) Convert a string to folded case. This function is mainly
useful for performing caseless (also known as case insensitive)
string comparisons.

A string x is a caseless match for a string y if and only if:

toCaseFold x == toCaseFold y

The result string may be longer than the input string, and may
differ from applying toLower to the input string. For instance,
the Armenian small ligature "ﬓ" (men now, U+FB13) is case
folded to the sequence "մ" (men, U+0574) followed by
"ն" (now, U+0576), while the Greek "µ" (micro sign,
U+00B5) is case folded to "μ" (small letter mu, U+03BC)
instead of itself.

O(n) Convert a string to lower case, using simple case
conversion. The result string may be longer than the input string.
For instance, "İ" (Latin capital letter I with dot above,
U+0130) maps to the sequence "i" (Latin small letter i, U+0069) followed
by " ̇" (combining dot above, U+0307).

O(n) Convert a string to upper case, using simple case
conversion. The result string may be longer than the input string.
For instance, the German "ß" (eszett, U+00DF) maps to the
two-letter sequence "SS".

The mapAccumR function behaves like a combination of map and
a strict foldr; it applies a function to each element of a
Text, passing an accumulating parameter from right to left, and
returning a final value of this accumulator together with the new
Text.

Generation and unfolding

O(n), where n is the length of the result. The unfoldr
function is analogous to the List unfoldr. unfoldr builds a
Text from a seed value. The function takes the element and
returns Nothing if it is done producing the Text, otherwise
Just(a,b). In this case, a is the next Char in the
string, and b is the seed value for further production. Subject
to fusion.

O(n) Like unfoldr, unfoldrN builds a Text from a seed
value. However, the length of the result should be limited by the
first argument to unfoldrN. This function is more efficient than
unfoldr when the maximum length of the result is known and
correct, otherwise its performance is similar to unfoldr. Subject
to fusion.

O(n)spanBy, applied to a predicate p and text t, returns
a pair whose first element is the longest prefix (possibly empty)
of t of elements that satisfy p, and whose second is the
remainder of the list.

O(n+m) Find the first instance of needle (which must be
non-null) in haystack. The first element of the returned tuple
is the prefix of haystack before needle is matched. The second
is the remainder of haystack, starting with the match.

O(n) Splits a Text into components delimited by separators,
where the predicate returns True for a separator element. The
resulting components do not contain the separators. Two adjacent
separators result in an empty component in the output. eg.

O(n) The partitionBy function takes a predicate and a Text,
and returns the pair of Texts with elements which do and do not
satisfy the predicate, respectively; i.e.

partitionBy p t == (filter p t, filter (not . p) t)

Indexing

If you think of a Text value as an array of Char values (which
it is not), you run the risk of writing inefficient code.

An idiom that is common in some languages is to find the numeric
offset of a character or substring, then use that number to split
or trim the searched string. With a Text value, this approach
would require two O(n) operations: one to perform the search, and
one to operate from wherever the search ended.

For example, suppose you have a string that you want to split on
the substring "::", such as "foo::bar::quux". Instead of
searching for the index of "::" and taking the substrings
before and after that index, you would instead use find "::".

Zipping and unzipping

O(n)zip takes two Texts and returns a list of
corresponding pairs of bytes. If one input Text is short,
excess elements of the longer Text are discarded. This is
equivalent to a pair of unpack operations.