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

Safe HaskellSafe
LanguageHaskell98

Streaming.Eversion.Pipes

Contents

Description

Like Streaming.Eversion, but for Producer folds and transformations.

Synopsis

Producer folds

evert Source #

Arguments

:: (forall m r. Monad m => Producer a m r -> m (x, r)) 
-> Fold a x 

evertM Source #

Arguments

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

evertM_ Source #

Arguments

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

evertMIO Source #

Arguments

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

evertMIO_ Source #

Arguments

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

Producer transformations

transvert Source #

Arguments

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

transvertM Source #

Arguments

:: Monad m 
=> (forall t r. (MonadTrans t, Monad (t m)) => Producer a (t m) r -> Producer 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)) => Producer a (t m) r -> Producer b (t m) r) 
-> FoldM m b x 
-> FoldM m a x 

Examples

Applying a decoder from Pipes.Text.Encoding to the inputs of a Fold. In case the decoding fails, part of the leftovers are read in order to build the error value.

>>> :{
    let trans = transvertM (\producer -> do result <- PT.decode (PT.utf8 . PT.eof) producer 
                                            lift (case result of
                                                    Left ls -> sample ls >>= lift . throwE
                                                    Right r -> return r))
        sample leftovers = L.purely P.fold L.mconcat (void (view (PB.splitAt 5) leftovers))
    in  runExceptT $ L.foldM (trans (L.generalize L.mconcat)) ["decode","this"]
    :}
Right "decodethis"
>>> :{
    let trans = transvertM (\producer -> do result <- PT.decode (PT.utf8 . PT.eof) producer 
                                            lift (case result of
                                                    Left ls -> sample ls >>= lift . throwE
                                                    Right r -> return r))
        sample leftovers = L.purely P.fold L.mconcat (void (view (PB.splitAt 8) leftovers))
    in  runExceptT $ L.foldM (trans (L.generalize L.mconcat)) ["invalid \xc3\x28","sequence"]
    :}
Left "\195(sequen"

Note that the errors are thrown in an ExceptT layer below the Producer and the polymorphic transformer.