HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletext-2.1.3Haskell2010

Data.Text.Internal.Fusion.Common

Warning: this is an internal module, and does not have a stable API or name. Functions in this module may not check or enforce preconditions expected by public modules. Use at your own risk!

This module provides a common stream fusion interface for text. The stream interface allows us to write text pipelines which do not allocate intermediate text values. For example, we could guarantee no intermediate text is allocated by writing the following:

  getNucleotides :: Text -> Text
  getNucleotides =
        unstream
      . filter isNucleotide
      . toLower
      . stream
    where
      isNucleotide chr =
        chr == 'a' ||
        chr == 'c' ||
        chr == 't' ||
        chr == 'g'
  • 54 values
  • Packagetext-2.1.3
  • Exports54
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceCommon.hs

Creation and elimination

4 declarations

Basic interface

12 declarations
valuecompareLengthI :: Integral a => Stream Char -> a -> Ordering
#

O(n) Compares the count of characters in a string to a number.

This function gives the same answer as comparing against the result of lengthI, but can short circuit if the count of characters is greater than the number or if the stream can't possibly be as long as the number supplied, and hence be more efficient.

Transformations

3 declarations

Case conversion

With Unicode text, it is incorrect to use combinators like map toUpper to case convert each character of a string individually. Instead, use the whole-string case conversion functions from this module. For correctness in different writing systems, these functions may map one input character to two or three output characters.

O(n) Convert a string to folded case. This function is mainly useful for performing caseless (or 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 bigram men now (U+0574 U+0576), while the micro sign (U+00B5) is case folded to the Greek small letter letter mu (U+03BC) instead of itself.

valuetoLower :: Stream Char -> Stream Char
#

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

Properties

 Data.Text.Internal.unstream . toLower . stream = toLower
valuetoTitle :: Stream Char -> Stream Char
#

O(n) Convert a string to title case, using simple case conversion.

The first letter (as determined by isLetter) of the input is converted to title case, as is every subsequent letter that immediately follows a non-letter. Every letter that immediately follows another letter is converted to lower case.

The result string may be longer than the input string. For example, the Latin small ligature fl (U+FB02) is converted to the sequence Latin capital letter F (U+0046) followed by Latin small letter l (U+006C).

This function is not idempotent. Consider lower-case letter ʼn (U+0149 LATIN SMALL LETTER N PRECEDED BY APOSTROPHE). Then toTitle "ʼn" = "ʼN": the first (and the only) letter of the input is converted to title case, becoming two letters. Now ʼ (U+02BC MODIFIER LETTER APOSTROPHE) is a modifier letter and as such is recognised as a letter by isLetter, so toTitle "ʼN" = "'n".

Note: this function does not take language or culture specific rules into account. For instance, in English, different style guides disagree on whether the book name "The Hill of the Red Fox" is correctly title cased—but this function will capitalize every word.

Properties

 Data.Text.Internal.unstream . toTitle . stream = toTitle
valuetoUpper :: Stream Char -> Stream Char
#

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.

Properties

 Data.Text.Internal.unstream . toUpper . stream = toUpper

Justification

Folds

7 declarations
valuefoldl :: (b -> Char -> b) -> b -> Stream Char -> b
#

foldl, applied to a binary operator, a starting value (typically the left-identity of the operator), and a Stream, reduces the Stream using the binary operator, from left to right.

Properties

 foldl f z0 . stream = foldl f z0
valuefoldr :: (Char -> b -> b) -> b -> Stream Char -> b
#

foldr, applied to a binary operator, a starting value (typically the right-identity of the operator), and a stream, reduces the stream using the binary operator, from right to left.

Properties

 foldr f z0 . stream = foldr f z0

Special folds

valueany :: (Char -> Bool) -> Stream Char -> Bool
#

O(n) any p xs determines if any character in the stream xs satisfies the predicate p.

Properties

any f . Data.Text.Fusion.stream = any f
valueall :: (Char -> Bool) -> Stream Char -> Bool
#

O(n) all p xs determines if all characters in the Text xs satisfy the predicate p.

Properties

all f . Data.Text.Fusion.stream = all f

Construction

0 declarations

Scans

Generation and unfolding

valueunfoldr :: (a -> Maybe (Char, a)) -> a -> Stream Char
#

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

Properties

unstream . unfoldr f z = unfoldr f z

Substrings

0 declarations

Breaking strings

Predicates

1 declaration

Searching

2 declarations

Indexing

4 declarations

Zipping and unzipping

1 declaration