text-0.2: An efficient packed Unicode text type

PortabilityGHC
Stabilityexperimental
Maintainerbos@serpentine.com, rtharper@aftereternity.co.uk, duncan@haskell.org

Data.Text.Fusion

Contents

Description

Text manipulation functions represented as fusible operations over streams.

Synopsis

Types

data Stream a Source

Constructors

forall s . Stream (s -> Step s a) !s !Int 

Instances

Eq a => Eq (Stream a) 
Ord a => Ord (Stream a) 

data Step s a Source

Constructors

Done 
Skip !s 
Yield !a !s 

Instances

Show a => Show (Step s a) 

Creation and elimination

stream :: Text -> Stream CharSource

O(n) Convert a Text into a 'Stream Char'.

unstream :: Stream Char -> TextSource

O(n) Convert a 'Stream Char' into a Text.

reverseStream :: Text -> Stream CharSource

O(n) Convert a Text into a 'Stream Char', but iterate backwards.

Transformations

reverse :: Stream Char -> TextSource

O(n) Reverse the characters of a string.

Construction

Scans

reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream CharSource

O(n) Perform the equivalent of scanr over a list, only with the input and result reversed.

Generation and unfolding

unfoldrN :: Int -> (a -> Maybe (Char, a)) -> a -> Stream CharSource

O(n) Like unfoldr, unfoldrN builds a stream from a seed value. However, the length of the result is limited by the first argument to unfoldrN. This function is more efficient than unfoldr when the length of the result is known.

Indexing

index :: Stream Char -> Int -> CharSource

O(n) stream index (subscript) operator, starting from 0.

findIndex :: (Char -> Bool) -> Stream Char -> Maybe IntSource

The findIndex function takes a predicate and a stream and returns the index of the first element in the stream satisfying the predicate.

findIndices :: (Char -> Bool) -> Stream Char -> [Int]Source

The findIndices function takes a predicate and a stream and returns all indices of the elements in the stream satisfying the predicate.

findIndexOrEnd :: (Char -> Bool) -> Stream Char -> IntSource

The findIndexOrEnd function takes a predicate and a stream and returns the index of the first element in the stream satisfying the predicate.

elemIndex :: Char -> Stream Char -> Maybe IntSource

O(n) The elemIndex function returns the index of the first element in the given stream which is equal to the query element, or Nothing if there is no such element.

elemIndices :: Char -> Stream Char -> [Int]Source

O(n) The elemIndices function returns the index of every element in the given stream which is equal to the query element.

count :: Char -> Stream Char -> IntSource

O(n) The count function returns the number of times the query element appears in the given stream.