iteratee-0.8.9.5: Iteratee-based I/O

Safe Haskell | None
Language | Haskell2010

Data.Iteratee.PTerm

Contents

- Nested iteratee combinators
- ListLike analog functions

Description

Enumeratees - pass terminals variant.

Provides enumeratees that pass terminal markers (`EOF`) to the inner `iteratee`.

Most enumeratees, upon receipt of `EOF`, will enter a done state and return the inner iteratee without sending `EOF` to it. This allows for composing enumerators as in:

    myEnum extraData i = do
    nested <- enumFile "file" (mapChunks unpacker i)
    inner <- run nested
    enumList extraData inner

if `mapChunks unpacker` sent `EOF` to the inner iteratee `i`, there would be no way to submit extra data to it after `run`ing the result from `enumFile`.

In certain cases, this is not the desired behavior. Consider:

    consumer :: Iteratee String IO ()
    consumer = liftI (go 0)
      where
        go c (Chunk xs) = liftIO (putStr s) >> liftI (go c)
        go 10 e         = liftIO (putStr "10 loops complete")
                            >> idone () (Chunk "")
        go n  e         = I.seek 0 >> liftI (go (n+1))

The `consumer` iteratee does not complete until after it has received 10 `EOF`s. If you attempt to use it in a standard enumeratee, it will never terminate. When the outer enumeratee is terminated, the inner iteratee will remain in a `cont` state, but in general there is no longer any valid data for the continuation. The enumeratee itself must pass the EOF marker to the inner iteratee and remain in a cont state until the inner iteratee signals its completion.

All enumeratees in this module will pass `EOF` terminators to the inner iteratees.

Synopsis

- mapChunksPT :: NullPoint s => (s -> s') -> Enumeratee s s' m a
- mapChunksMPT :: (Monad m, NullPoint s, Nullable s) => (s -> m s') -> Enumeratee s s' m a
- convStreamPT :: (Monad m, Nullable s, NullPoint s') => Iteratee s m s' -> Enumeratee s s' m a
- unfoldConvStreamPT :: (Monad m, Nullable s, NullPoint s') => (acc -> Iteratee s m (acc, s')) -> acc -> Enumeratee s s' m a
- unfoldConvStreamCheckPT :: (Monad m, Nullable elo) => (((Stream eli -> Iteratee eli m a) -> Maybe SomeException -> Iteratee elo m (Iteratee eli m a)) -> Enumeratee elo eli m a) -> (acc -> Iteratee elo m (acc, eli)) -> acc -> Enumeratee elo eli m a
- breakEPT :: (ListLike s el, NullPoint s) => (el -> Bool) -> Enumeratee s s m a
- takePT :: (Monad m, Nullable s, ListLike s el) => Int -> Enumeratee s s m a
- takeUpToPT :: (Monad m, Nullable s, ListLike s el) => Int -> Enumeratee s s m a
- takeWhileEPT :: (ListLike s el, NullPoint s) => (el -> Bool) -> Enumeratee s s m a
- mapStreamPT :: (ListLike (s el) el, ListLike (s el') el', NullPoint (s el), LooseMap s el el') => (el -> el') -> Enumeratee (s el) (s el') m a
- rigidMapStreamPT :: (ListLike s el, NullPoint s) => (el -> el) -> Enumeratee s s m a
- filterPT :: (Monad m, Functor m, Nullable s, ListLike s el) => (el -> Bool) -> Enumeratee s s m a

# Nested iteratee combinators

mapChunksPT :: NullPoint s => (s -> s') -> Enumeratee s s' m a

Convert one stream into another with the supplied mapping function.

A version of `mapChunks` that sends `EOF`s to the inner iteratee.

mapChunksMPT :: (Monad m, NullPoint s, Nullable s) => (s -> m s') -> Enumeratee s s' m a

Convert a stream of `s` to a stream of `s'` using the supplied function.

A version of `mapChunksM` that sends `EOF`s to the inner iteratee.

convStreamPT :: (Monad m, Nullable s, NullPoint s') => Iteratee s m s' -> Enumeratee s s' m a

Convert one stream into another, not necessarily in lockstep.

A version of `convStream` that sends `EOF`s to the inner iteratee.

unfoldConvStreamPT :: (Monad m, Nullable s, NullPoint s') => (acc -> Iteratee s m (acc, s')) -> acc -> Enumeratee s s' m a

The most general stream converter.

A version of `unfoldConvStream` that sends `EOF`s to the inner iteratee.

unfoldConvStreamCheckPT :: (Monad m, Nullable elo) => (((Stream eli -> Iteratee eli m a) -> Maybe SomeException -> Iteratee elo m (Iteratee eli m a)) -> Enumeratee elo eli m a) -> (acc -> Iteratee elo m (acc, eli)) -> acc -> Enumeratee elo eli m a

A version of `unfoldConvStreamCheck` that sends `EOF`s to the inner iteratee.

# ListLike analog functions

breakEPT :: (ListLike s el, NullPoint s) => (el -> Bool) -> Enumeratee s s m a

A variant of `breakE` that passes `EOF`s.

takePT

Arguments

:: (Monad m, Nullable s, ListLike s el) |
=> Int | number of elements to consume
-> Enumeratee s s m a |

A variant of `take` that passes `EOF`s.

takeUpToPT :: (Monad m, Nullable s, ListLike s el) => Int -> Enumeratee s s m a

A variant of `takeUpTo` that passes `EOF`s.

takeWhileEPT :: (ListLike s el, NullPoint s) => (el -> Bool) -> Enumeratee s s m a

A variant of `takeWhileE` that passes `EOF`s.

mapStreamPT :: (ListLike (s el) el, ListLike (s el') el', NullPoint (s el), LooseMap s el el') => (el -> el') -> Enumeratee (s el) (s el') m a

A variant of `mapStream` that passes `EOF`s.

rigidMapStreamPT :: (ListLike s el, NullPoint s) => (el -> el) -> Enumeratee s s m a

A variant of `rigidMapStream` that passes `EOF`s.

filterPT :: (Monad m, Functor m, Nullable s, ListLike s el) => (el -> Bool) -> Enumeratee s s m a

A variant of `filter` that passes `EOF`s.