fay-base-0.19.4.1: The base package for Fay.

Safe HaskellNone

Data.Text

Contents

Description

Compatible API with the text package.

Synopsis

Documentation

data Text Source

A space efficient, packed, unboxed Unicode text type.

Instances

Eq Text 
Data Text 
Typeable Text 
IsString Text 

Creation and elimination

pack :: String -> TextSource

O(n) Convert a String into a Text. Subject to fusion. Performs replacement on invalid scalar values.

unpack :: Text -> StringSource

O(n) Convert a Text into a String. Subject to fusion.

fromString :: String -> TextSource

Convert from a string to text.

empty :: TextSource

O(1) The empty Text.

Conversions

I/O

Breaking into many substrings

splitOn :: Char -> Text -> [Text]Source

O(m+n) Break a Text into pieces separated by the first Text argument, consuming the delimiter. An empty delimiter is invalid, and will cause an error to be raised.

stripSuffixSource

Arguments

:: Text

Suffix.

-> Text

Text.

-> Maybe Text 

O(n) Return the prefix of the second string if its suffix matches the entire first string.

Basic interface

cons :: Char -> Text -> TextSource

O(n) Adds a character to the front of a Text. This function is more costly than its List counterpart because it requires copying a new array. Subject to fusion. Performs replacement on invalid scalar values.

snoc :: Text -> Char -> TextSource

O(n) Adds a character to the end of a Text. This copies the entire array in the process, unless fused. Subject to fusion. Performs replacement on invalid scalar values.

append :: Text -> Text -> TextSource

O(n) Appends one Text to the other by copying both of them into a new Text. Subject to fusion.

(<>) :: Text -> Text -> TextSource

Append two texts.

uncons :: Text -> Maybe (Char, Text)Source

O(1) Returns the first character and rest of a Text, or Nothing if empty. Subject to fusion.

head :: Text -> CharSource

O(1) Returns the first character of a Text, which must be non-empty. Subject to fusion.

init :: Text -> TextSource

O(1) Returns all but the last character of a Text, which must be non-empty. Subject to fusion.

last :: Text -> CharSource

O(1) Returns the last character of a Text, which must be non-empty. Subject to fusion.

tail :: Text -> TextSource

O(1) Returns all characters after the head of a Text, which must be non-empty. Subject to fusion.

null :: Text -> BoolSource

O(1) Tests whether a Text is empty or not. Subject to fusion.

length :: Text -> IntSource

O(n) Returns the number of characters in a Text. Subject to fusion.

Special folds

maximum :: Text -> CharSource

O(n) maximum returns the maximum value from a Text, which must be non-empty. Subject to fusion.

all :: (Char -> Bool) -> Text -> BoolSource

O(n) all p t determines whether all characters in the Text t satisify the predicate p. Subject to fusion.

any :: (Char -> Bool) -> Text -> BoolSource

O(n) any p t determines whether any character in the Text t satisifes the predicate p. Subject to fusion.

concatMap :: (Char -> Text) -> Text -> TextSource

O(n) Map a function over a Text that results in a Text, and concatenate the results.

concat :: [Text] -> TextSource

O(n) Concatenate a list of Texts.

minimum :: Text -> CharSource

O(n) minimum returns the minimum value from a Text, which must be non-empty. Subject to fusion.

Case conversion

toLower :: Text -> TextSource

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).

Transformations

map :: (Char -> Char) -> Text -> TextSource

O(n) map f t is the Text obtained by applying f to each element of t. Subject to fusion. Performs replacement on invalid scalar values.

intercalate :: Text -> [Text] -> TextSource

O(n) The intercalate function takes a Text and a list of Texts and concatenates the list after interspersing the first argument between each element of the list.

intersperse :: Char -> Text -> TextSource

O(n) The intersperse function takes a character and places it between the characters of a Text. Subject to fusion. Performs replacement on invalid scalar values.

reverse :: Text -> TextSource

O(n) Reverse the characters of a string. Subject to fusion.

Predicates

isPrefixOf :: Text -> Text -> BoolSource

O(n) The isPrefixOf function takes two Texts and returns True iff the first is a prefix of the second. Subject to fusion. http:docs.closure-library.googlecode.comgitclosure_goog_string_string.js.source.html

Substrings

drop :: Int -> Text -> TextSource

O(n) drop n, applied to a Text, returns the suffix of the Text after the first n characters, or the empty Text if n is greater than the length of the Text. Subject to fusion.

take :: Int -> Text -> TextSource

O(n) take n, applied to a Text, returns the prefix of the Text of length n, or the Text itself if n is greater than the length of the Text. Subject to fusion.

Breaking into lines and words

unlines :: [Text] -> TextSource

O(n) Joins lines, after appending a terminating newline to each.

lines :: Text -> [Text]Source

O(n) Breaks a Text up into a list of Texts at newline Chars. The resulting strings do not contain newlines.