Data.Enumerator.List

enumerator-0.4.20: Reliable, high-performance processing with left-fold enumerators

Copyright | 2010-2011 John Millikin
License | MIT
Maintainer | jmillikin@gmail.com
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.Enumerator.List

Contents

- List analogues
  - Folds
  - Maps
  - Accumulating maps
  - Infinite streams
  - Bounded streams
  - Dropping input
  - Consumers
  - Zipping
  - Unsorted

Description

This module is intended to be imported qualified:

    import qualified Data.Enumerator.List as EL

Since: 0.4.5

Synopsis

- fold :: Monad m => (b -> a -> b) -> b -> Iteratee a m b
- foldM :: Monad m => (b -> a -> m b) -> b -> Iteratee a m b
- map :: Monad m => (ao -> ai) -> Enumeratee ao ai m b
- mapM :: Monad m => (ao -> m ai) -> Enumeratee ao ai m b
- mapM_ :: Monad m => (a -> m b) -> Iteratee a m ()
- concatMap :: Monad m => (ao -> [ai]) -> Enumeratee ao ai m b
- concatMapM :: Monad m => (ao -> m [ai]) -> Enumeratee ao ai m b
- mapAccum :: Monad m => (s -> ao -> (s, ai)) -> s -> Enumeratee ao ai m b
- mapAccumM :: Monad m => (s -> ao -> m (s, ai)) -> s -> Enumeratee ao ai m b
- concatMapAccum :: Monad m => (s -> ao -> (s, [ai])) -> s -> Enumeratee ao ai m b
- concatMapAccumM :: Monad m => (s -> ao -> m (s, [ai])) -> s -> Enumeratee ao ai m b
- iterate :: Monad m => (a -> a) -> a -> Enumerator a m b
- iterateM :: Monad m => (a -> m a) -> a -> Enumerator a m b
- repeat :: Monad m => a -> Enumerator a m b
- repeatM :: Monad m => m a -> Enumerator a m b
- replicate :: Monad m => Integer -> a -> Enumerator a m b
- replicateM :: Monad m => Integer -> m a -> Enumerator a m b
- generateM :: Monad m => m (Maybe a) -> Enumerator a m b
- unfold :: Monad m => (s -> Maybe (a, s)) -> s -> Enumerator a m b
- unfoldM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Enumerator a m b
- drop :: Monad m => Integer -> Iteratee a m ()
- dropWhile :: Monad m => (a -> Bool) -> Iteratee a m ()
- filter :: Monad m => (a -> Bool) -> Enumeratee a a m b
- filterM :: Monad m => (a -> m Bool) -> Enumeratee a a m b
- unique :: (Ord a, Monad m) => Enumeratee a a m b
- head :: Monad m => Iteratee a m (Maybe a)
- head_ :: Monad m => Iteratee a m a
- take :: Monad m => Integer -> Iteratee a m [a]
- takeWhile :: Monad m => (a -> Bool) -> Iteratee a m [a]
- consume :: Monad m => Iteratee a m [a]
- zip :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m (b1, b2)
- zip3 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m (b1, b2, b3)
- zip4 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m (b1, b2, b3, b4)
- zip5 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m (b1, b2, b3, b4, b5)
- zip6 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m (b1, b2, b3, b4, b5, b6)
- zip7 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m b7 -> Iteratee a m (b1, b2, b3, b4, b5, b6, b7)
- zipWith :: Monad m => (b1 -> b2 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m c
- zipWith3 :: Monad m => (b1 -> b2 -> b3 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m c
- zipWith4 :: Monad m => (b1 -> b2 -> b3 -> b4 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m c
- zipWith5 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m c
- zipWith6 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> b6 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m c
- zipWith7 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> b6 -> b7 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m b7 -> Iteratee a m c
- require :: Monad m => Integer -> Iteratee a m ()
- isolate :: Monad m => Integer -> Enumeratee a a m b
- isolateWhile :: Monad m => (a -> Bool) -> Enumeratee a a m b
- splitWhen :: Monad m => (a -> Bool) -> Enumeratee a [a] m b

# List analogues

## Folds

fold :: Monad m => (b -> a -> b) -> b -> Iteratee a m b

Consume the entire input stream with a strict left fold, one element at a time.

Since: 0.4.8

foldM :: Monad m => (b -> a -> m b) -> b -> Iteratee a m b

Consume the entire input stream with a strict monadic left fold, one element at a time.

Since: 0.4.8

## Maps

map :: Monad m => (ao -> ai) -> Enumeratee ao ai m b

``map` f` applies f to each input element and feeds the resulting outputs to the inner iteratee.

Since: 0.4.8

mapM :: Monad m => (ao -> m ai) -> Enumeratee ao ai m b

``mapM` f` applies f to each input element and feeds the resulting outputs to the inner iteratee.

Since: 0.4.8

mapM_ :: Monad m => (a -> m b) -> Iteratee a m ()

``mapM_` f` applies f to each input element, and discards the results.

Since: 0.4.11

concatMap :: Monad m => (ao -> [ai]) -> Enumeratee ao ai m b

``concatMap` f` applies f to each input element and feeds the resulting outputs to the inner iteratee.

Since: 0.4.8

concatMapM :: Monad m => (ao -> m [ai]) -> Enumeratee ao ai m b

``concatMapM` f` applies f to each input element and feeds the resulting outputs to the inner iteratee.

Since: 0.4.8

## Accumulating maps

mapAccum :: Monad m => (s -> ao -> (s, ai)) -> s -> Enumeratee ao ai m b

Similar to `map`, but with a stateful step function.

Since: 0.4.9

mapAccumM :: Monad m => (s -> ao -> m (s, ai)) -> s -> Enumeratee ao ai m b

Similar to `mapM`, but with a stateful step function.

Since: 0.4.9

concatMapAccum :: Monad m => (s -> ao -> (s, [ai])) -> s -> Enumeratee ao ai m b

Similar to `concatMap`, but with a stateful step function.

Since: 0.4.11

concatMapAccumM :: Monad m => (s -> ao -> m (s, [ai])) -> s -> Enumeratee ao ai m b

Similar to `concatMapM`, but with a stateful step function.

Since: 0.4.11

## Infinite streams

iterate :: Monad m => (a -> a) -> a -> Enumerator a m b

``iterate` f x` enumerates an infinite stream of repeated applications of f to x.

Analogous to `iterate`.

Since: 0.4.8

iterateM :: Monad m => (a -> m a) -> a -> Enumerator a m b

Similar to `iterate`, except the iteration function is monadic.

Since: 0.4.8

repeat :: Monad m => a -> Enumerator a m b

Enumerates an infinite stream of a single element.

Analogous to `repeat`.

Since: 0.4.8

repeatM :: Monad m => m a -> Enumerator a m b

Enumerates an infinite stream of element. Each element is computed by the underlying monad.

Since: 0.4.8

## Bounded streams

replicate :: Monad m => Integer -> a -> Enumerator a m b

``replicate` n x` enumerates a stream containing n copies of x.

Analogous to `replicate`.

Since: 0.4.8

replicateM :: Monad m => Integer -> m a -> Enumerator a m b

``replicateM` n m_x` enumerates a stream of n elements, with each element computed by m_x.

Since: 0.4.8

generateM :: Monad m => m (Maybe a) -> Enumerator a m b

Like `repeatM`, except the computation may terminate the stream by returning `Nothing`.

Since: 0.4.8

unfold :: Monad m => (s -> Maybe (a, s)) -> s -> Enumerator a m b

Enumerates a stream of elements by repeatedly applying a function to some state.

Similar to `iterate`.

Since: 0.4.8

unfoldM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Enumerator a m b

Enumerates a stream of elements by repeatedly applying a computation to some state.

Similar to `iterateM`.

Since: 0.4.8

## Dropping input

drop :: Monad m => Integer -> Iteratee a m ()

``drop` n` ignores n input elements from the stream.

Since: 0.4.5

dropWhile :: Monad m => (a -> Bool) -> Iteratee a m ()

``dropWhile` p` ignores input from the stream until the first element which does not match the predicate.

Since: 0.4.5

filter :: Monad m => (a -> Bool) -> Enumeratee a a m b

Applies a predicate to the stream. The inner iteratee only receives elements for which the predicate is `True`.

Since: 0.4.8

filterM :: Monad m => (a -> m Bool) -> Enumeratee a a m b

Applies a monadic predicate to the stream. The inner iteratee only receives elements for which the predicate returns `True`.

Since: 0.4.8

unique :: (Ord a, Monad m) => Enumeratee a a m b

Remove duplicate elements from a stream, passing through the first instance of each value.

Similar to `nub`, but more efficient because it uses a `Set` internally.

Since: 0.4.11

## Consumers

head :: Monad m => Iteratee a m (Maybe a)

Get the next element from the stream, or `Nothing` if the stream has ended.

Since: 0.4.5

head_ :: Monad m => Iteratee a m a

Get the next element from the stream, or raise an error if the stream has ended.

Since: 0.4.14

take :: Monad m => Integer -> Iteratee a m [a]

``take` n` extracts the next n elements from the stream, as a list.

Since: 0.4.5

takeWhile :: Monad m => (a -> Bool) -> Iteratee a m [a]

``takeWhile` p` extracts input from the stream until the first element which does not match the predicate.

Since: 0.4.5

consume :: Monad m => Iteratee a m [a]

    consume = takeWhile (const True)

Since: 0.4.5

## Zipping

zip :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m (b1, b2)

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee.

Analogous to `zip`.

Since: 0.4.14

zip3 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m (b1, b2, b3)

Pass input from a stream through three iteratees at once. Excess input is yielded if it was not consumed by any iteratee.

Analogous to `zip3`.

Since: 0.4.14

zip4 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m (b1, b2, b3, b4)

Pass input from a stream through four iteratees at once. Excess input is yielded if it was not consumed by any iteratee.

Analogous to `zip4`.

Since: 0.4.14

zip5 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m (b1, b2, b3, b4, b5)

Pass input from a stream through five iteratees at once. Excess input is yielded if it was not consumed by any iteratee.

Analogous to `zip5`.

Since: 0.4.14

zip6 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m (b1, b2, b3, b4, b5, b6)

Pass input from a stream through six iteratees at once. Excess input is yielded if it was not consumed by any iteratee.

Analogous to `zip6`.

Since: 0.4.14

zip7 :: Monad m => Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m b7 -> Iteratee a m (b1, b2, b3, b4, b5, b6, b7)

Pass input from a stream through seven iteratees at once. Excess input is yielded if it was not consumed by any iteratee.

Analogous to `zip7`.

Since: 0.4.14

zipWith :: Monad m => (b1 -> b2 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith`.

Since: 0.4.14

zipWith3 :: Monad m => (b1 -> b2 -> b3 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith3`.

Since: 0.4.14

zipWith4 :: Monad m => (b1 -> b2 -> b3 -> b4 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith4`.

Since: 0.4.14

zipWith5 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith5`.

Since: 0.4.14

zipWith6 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> b6 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith6`.

Since: 0.4.14

zipWith7 :: Monad m => (b1 -> b2 -> b3 -> b4 -> b5 -> b6 -> b7 -> c) -> Iteratee a m b1 -> Iteratee a m b2 -> Iteratee a m b3 -> Iteratee a m b4 -> Iteratee a m b5 -> Iteratee a m b6 -> Iteratee a m b7 -> Iteratee a m c

Pass input from a stream through two iteratees at once. Excess input is yielded if it was not consumed by either iteratee. Output from the iteratees is combined with a user-provided function.

Analogous to `zipWith7`.

Since: 0.4.14

## Unsorted

require :: Monad m => Integer -> Iteratee a m ()

``require` n` buffers input until at least n elements are available, or throws an error if the stream ends early.

Since: 0.4.5

isolate :: Monad m => Integer -> Enumeratee a a m b

``isolate` n` reads at most n elements from the stream, and passes them to its iteratee. If the iteratee finishes early, elements continue to be consumed from the outer stream until n have been consumed.

Since: 0.4.5

isolateWhile :: Monad m => (a -> Bool) -> Enumeratee a a m b

``isolateWhile` p` reads elements from the stream until p is false, and passes them to its iteratee. If the iteratee finishes early, elements continue to be consumed from the outer stream until p is false.

Since: 0.4.16

splitWhen :: Monad m => (a -> Bool) -> Enumeratee a [a] m b

Split on elements satisfying a given predicate.

Since: 0.4.8