Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Like Streaming.Eversion, but for Producer folds and transformations.
- evert :: (forall m r. Monad m => Producer a m r -> m (x, r)) -> Fold a x
- evertM :: Monad m => (forall t r. (MonadTrans t, Monad (t m)) => Producer a (t m) r -> t m (x, r)) -> FoldM m a x
- evertM_ :: Monad m => (forall t r. (MonadTrans t, Monad (t m)) => Producer a (t m) r -> t m r) -> FoldM m a ()
- evertMIO :: MonadIO m => (forall t r. (MonadTrans t, MonadIO (t m)) => Producer a (t m) r -> t m (x, r)) -> FoldM m a x
- evertMIO_ :: MonadIO m => (forall t r. (MonadTrans t, MonadIO (t m)) => Producer a (t m) r -> t m r) -> FoldM m a ()
- transvert :: (forall m r. Monad m => Producer a m r -> Producer b m r) -> Fold b x -> Fold a x
- transvertM :: 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 :: 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
Producer folds
:: Monad m | |
=> (forall t r. (MonadTrans t, Monad (t m)) => Producer a (t m) r -> t m (x, r)) | |
-> FoldM m a x |
:: Monad m | |
=> (forall t r. (MonadTrans t, Monad (t m)) => Producer a (t m) r -> t m r) | |
-> FoldM m a () |
:: MonadIO m | |
=> (forall t r. (MonadTrans t, MonadIO (t m)) => Producer a (t m) r -> t m (x, r)) | |
-> FoldM m a x |
:: MonadIO m | |
=> (forall t r. (MonadTrans t, MonadIO (t m)) => Producer a (t m) r -> t m r) | |
-> FoldM m a () |
Producer transformations
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.