Hi, I am learning pipes and trying to figure out the following example:
I have a stateful consumer, let's say a counter: counter :: (Show a) => Consumer a (StateT Integer IO) () counter = do x <- await lift $ S.modify (+1) liftIO $ print $ show x counter But how do I get the final state from it? The following code wouldn't work because the producer ("each") has value type of unit, and the consumer seems to be required to return the same value type: --this doesn't compile runEffect $ each [1,2,3,4,5,6] >-> PL.execState 0 counter Am I approaching the problem incorrectly? I'd like to have a pipeline that runs "normally", ideally even with "normal" stateless consumers, but also accumulates some data that is not needed for the pipeline itself, but is useful when it is finished. Something as simple as: each [1,2,3,4,5,6] >-> .... >-> P.print and that would return a count of elements handled by the pipeline when it has finished. Maybe I should be wrapping the whole producer into StateT, something like StateT (Producer a m r) m r? Then how to compose the pipeline with this type? Or what would be the way to solve this kind of problem? Cheers, Alexey. -- You received this message because you are subscribed to the Google Groups "Haskell Pipes" group. To unsubscribe from this group and stop receiving emails from it, send an email to haskell-pipes+unsubscr...@googlegroups.com. To post to this group, send email to haskell-pipes@googlegroups.com.