Portability | GHC |
---|---|
Stability | experimental |
Maintainer | rtharper@aftereternity.co.uk, bos@serpentine.com, duncan@haskell.org |
Text manipulation functions represented as fusible operations over streams.
- data Stream a = forall s . Stream (s -> Step s a) !s !Int
- data Step s a
- stream :: Text -> Stream Char
- unstream :: Stream Char -> Text
- reverseStream :: Text -> Stream Char
- empty :: Stream Char
- cons :: Char -> Stream Char -> Stream Char
- snoc :: Stream Char -> Char -> Stream Char
- append :: Stream Char -> Stream Char -> Stream Char
- uncons :: Stream Char -> Maybe (Char, Stream Char)
- head :: Stream Char -> Char
- tail :: Stream Char -> Stream Char
- last :: Stream Char -> Char
- init :: Stream Char -> Stream Char
- null :: Stream Char -> Bool
- length :: Stream Char -> Int
- eq :: Ord a => Stream a -> Stream a -> Bool
- map :: (Char -> Char) -> Stream Char -> Stream Char
- intercalate :: Stream Char -> [Stream Char] -> Stream Char
- intersperse :: Char -> Stream Char -> Stream Char
- reverse :: Stream Char -> Text
- foldl :: (b -> Char -> b) -> b -> Stream Char -> b
- foldl' :: (b -> Char -> b) -> b -> Stream Char -> b
- foldl1 :: (Char -> Char -> Char) -> Stream Char -> Char
- foldl1' :: (Char -> Char -> Char) -> Stream Char -> Char
- foldr :: (Char -> b -> b) -> b -> Stream Char -> b
- foldr1 :: (Char -> Char -> Char) -> Stream Char -> Char
- concat :: [Stream Char] -> Stream Char
- concatMap :: (Char -> Stream Char) -> Stream Char -> Stream Char
- any :: (Char -> Bool) -> Stream Char -> Bool
- all :: (Char -> Bool) -> Stream Char -> Bool
- maximum :: Stream Char -> Char
- minimum :: Stream Char -> Char
- scanl :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
- reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
- mapAccumL :: (a -> b -> (a, b)) -> a -> Stream b -> Stream b
- replicate :: Int -> Char -> Stream Char
- unfoldr :: (a -> Maybe (Char, a)) -> a -> Stream Char
- unfoldrN :: Int -> (a -> Maybe (Char, a)) -> a -> Stream Char
- take :: Int -> Stream Char -> Stream Char
- drop :: Int -> Stream Char -> Stream Char
- takeWhile :: (Char -> Bool) -> Stream Char -> Stream Char
- dropWhile :: (Char -> Bool) -> Stream Char -> Stream Char
- isPrefixOf :: Eq a => Stream a -> Stream a -> Bool
- elem :: Char -> Stream Char -> Bool
- filter :: (Char -> Bool) -> Stream Char -> Stream Char
- find :: (Char -> Bool) -> Stream Char -> Maybe Char
- index :: Stream Char -> Int -> Char
- findIndex :: (Char -> Bool) -> Stream Char -> Maybe Int
- findIndices :: (Char -> Bool) -> Stream Char -> [Int]
- findIndexOrEnd :: (Char -> Bool) -> Stream Char -> Int
- elemIndex :: Char -> Stream Char -> Maybe Int
- elemIndices :: Char -> Stream Char -> [Int]
- count :: Char -> Stream Char -> Int
- zipWith :: (Char -> Char -> Char) -> Stream Char -> Stream Char -> Stream Char
Types
Creation and elimination
reverseStream :: Text -> Stream CharSource
O(n) Convert a Text
into a 'Stream Char', but iterate
backwards.
Basic interface
cons :: Char -> Stream Char -> Stream CharSource
O(n) Adds a character to the front of a Stream Char.
uncons :: Stream Char -> Maybe (Char, Stream Char)Source
O(1) Returns the first character and remainder of a 'Stream
Char', or Nothing
if empty. Subject to array fusion.
head :: Stream Char -> CharSource
O(1) Returns the first character of a Text, which must be non-empty. Subject to array fusion.
tail :: Stream Char -> Stream CharSource
O(1) Returns all characters after the head of a Stream Char, which must be non-empty.
last :: Stream Char -> CharSource
O(n) Returns the last character of a 'Stream Char', which must be non-empty.
init :: Stream Char -> Stream CharSource
O(1) Returns all but the last character of a Stream Char, which must be non-empty.
Transformations
map :: (Char -> Char) -> Stream Char -> Stream CharSource
O(n) map
f
xs is the Stream Char obtained by applying f
to each element of
xs
.
intersperse :: Char -> Stream Char -> Stream CharSource
O(n) Take a character and place it between each of the characters of a 'Stream Char'.
Folds
foldl :: (b -> Char -> b) -> b -> Stream Char -> bSource
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.
foldl1 :: (Char -> Char -> Char) -> Stream Char -> CharSource
foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty Streams.
foldr :: (Char -> b -> b) -> b -> Stream Char -> bSource
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.
foldr1 :: (Char -> Char -> Char) -> Stream Char -> CharSource
foldr1 is a variant of foldr
that has no starting value argument,
and thus must be applied to non-empty streams.
Subject to array fusion.
Special folds
concat :: [Stream Char] -> Stream CharSource
O(n) Concatenate a list of streams. Subject to array fusion.
concatMap :: (Char -> Stream Char) -> Stream Char -> Stream CharSource
Map a function over a stream that results in a stream and concatenate the results.
any :: (Char -> Bool) -> Stream Char -> BoolSource
O(n) any p
xs determines if any character in the stream
xs
satisifes the predicate p
.
all :: (Char -> Bool) -> Stream Char -> BoolSource
O(n) all p
xs determines if all characters in the Text
xs
satisify the predicate p
.
maximum :: Stream Char -> CharSource
O(n) maximum returns the maximum value from a stream, which must be non-empty.
minimum :: Stream Char -> CharSource
O(n) minimum returns the minimum value from a Text
, which must be
non-empty.
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.
Accumulating maps
mapAccumL :: (a -> b -> (a, b)) -> a -> Stream b -> Stream bSource
O(n) Like a combination of map
and foldl
. Applies a
function to each element of a stream, passing an accumulating
parameter from left to right, and returns a final stream.
Note: Unlike the version over lists, this function does not return a final value for the accumulator, because the nature of streams precludes it.
Generation and unfolding
unfoldr :: (a -> Maybe (Char, a)) -> a -> Stream CharSource
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.
Substrings
Breaking strings
take :: Int -> Stream Char -> Stream CharSource
O(n) take n, applied to a stream, returns the prefix of the
stream of length n
, or the stream itself if n
is greater than the
length of the stream.
drop :: Int -> Stream Char -> Stream CharSource
O(n) drop n, applied to a stream, returns the suffix of the
stream of length n
, or the empty stream if n
is greater than the
length of the stream.
takeWhile :: (Char -> Bool) -> Stream Char -> Stream CharSource
takeWhile, applied to a predicate p
and a stream, returns the
longest prefix (possibly empty) of elements that satisfy p.
dropWhile :: (Char -> Bool) -> Stream Char -> Stream CharSource
dropWhile p
xs returns the suffix remaining after takeWhile p
xs.
Predicates
isPrefixOf :: Eq a => Stream a -> Stream a -> BoolSource
O(n) The isPrefixOf
function takes two Stream
s and returns
True
iff the first is a prefix of the second.
Searching
filter :: (Char -> Bool) -> Stream Char -> Stream CharSource
O(n) filter
, applied to a predicate and a stream,
returns a stream containing those characters that satisfy the
predicate.
Indexing
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.
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.