streaming-eversion-0.4.0.0: Translate pull-based stream folds into push-based iteratees.

Safe HaskellSafe
LanguageHaskell98

Streaming.Eversion

Contents

Description

Most pull-to-push transformations in this module require functions that are polymorphic over a monad transformer.

Because of this, some of the type signatures look scary, but actually many (suitably polymorphic) operations on Streams will unify with them.

To get "interruptible" operations that can exit early with an error, put a ExceptT transformer just below the polymorphic monad transformer. In practice, that means lifting functions like throwE and hoistEither a number of times.

Inspired by http://pchiusano.blogspot.com.es/2011/12/programmatic-translation-to-iteratees.html

Synopsis

Stream folds

evert Source #

Arguments

:: (forall m r. Monad m => Stream (Of a) m r -> m (Of x r)) 
-> Fold a x 

evertM Source #

Arguments

:: Monad m 
=> (forall t r. (MonadTrans t, Monad (t m)) => Stream (Of a) (t m) r -> t m (Of x r)) 
-> FoldM m a x 

Like evert, but gives the stream-folding function access to a base monad.

>>> :{
    let consume stream = lift (putStrLn "x") >> S.effects stream
    in  L.foldM (evertM_ consume) ["a","b","c"]
    :}
x

Note however that control operations can't be lifted through the transformer.

evertM_ Source #

Arguments

:: Monad m 
=> (forall t r. (MonadTrans t, Monad (t m)) => Stream (Of a) (t m) r -> t m r) 
-> FoldM m a () 

evertMIO Source #

Arguments

:: MonadIO m 
=> (forall t r. (MonadTrans t, MonadIO (t m)) => Stream (Of a) (t m) r -> t m (Of x r)) 
-> FoldM m a x 

Like evertM, but gives the stream-consuming function the ability to use liftIO.

>>> L.foldM (evertMIO_ S.print) ["a","b","c"]
"a"
"b"
"c"

evertMIO_ Source #

Arguments

:: MonadIO m 
=> (forall t r. (MonadTrans t, MonadIO (t m)) => Stream (Of a) (t m) r -> t m r) 
-> FoldM m a () 

Stream transformations

transvert Source #

Arguments

:: (forall m r. Monad m => Stream (Of a) m r -> Stream (Of b) m r) 
-> Fold b x 
-> Fold a x 

transvertM Source #

Arguments

:: Monad m 
=> (forall t r. (MonadTrans t, Monad (t m)) => Stream (Of a) (t m) r -> Stream (Of b) (t m) r) 
-> FoldM m b x 
-> FoldM m a x 

transvertMIO Source #

Arguments

:: MonadIO m 
=> (forall t r. (MonadTrans t, MonadIO (t m)) => Stream (Of a) (t m) r -> Stream (Of b) (t m) r) 
-> FoldM m b x 
-> FoldM m a x 

Internals

generalEvertM Source #

Arguments

:: Monad m 
=> (forall r. Stream (Of a) (Stream ((->) (Feed a)) m) r -> Stream ((->) (Feed a)) m (Of b r)) 
-> FoldM m a b 

generalTransvertM Source #

Arguments

:: Monad m 
=> (forall r. Stream (Of a) (Stream ((->) (Feed a)) m) r -> Stream (Of b) (Stream ((->) (Feed a)) m) r) 
-> FoldM m b x 
-> FoldM m a x