Help with Data.Conduit.List.mapAccum

Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like : testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s ->(x+s, x) 0 I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ? Bruno

Foldl from conduit combinators?
On Tue, Jun 14, 2016 at 22:54
Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like :
testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s -> (x+s, x) 0
I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ?
Bruno
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Hello,
Thanks for the answer.
I could of course use fold, but that would eliminate the use of mapAccum, what's the use of it then if I cannot get the result ?
It's also a broader question, how to get the result of a ConduitM i o m r ?
bruno
On 15 Jun 2016 08:08 +0200, Baojun Wang
Foldl from conduit combinators? On Tue, Jun 14, 2016 at 22:54
wrote: Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like :
testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s ->(x+s, x) 0
I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ?
Bruno
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org(mailto:Haskell-Cafe@haskell.org) http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

If I understand the question correctly, what you're saying is:
* My upstream (testC) is both returning a result _and_ yielding a stream of
values downstream
* My downstream (CL.consume) is collecting those values and returning a
result based on them
* How can I capture both the upstream and downstream results?
If so, this is the section of the docs with the relevant functions[1]. It
provides a few different fusion functions to combine an upstream and
downstream without throwing away the upstream result (which is the default
behavior of conduit, for various design and usability reasons). In your
case, this may look something like:
runConduit (fuseBoth testC CL.consume)
Michael
[1]
https://s3.amazonaws.com/haddock.stackage.org/lts-6.3/conduit-1.2.6.6/Data-C...
On Wed, Jun 15, 2016 at 8:53 AM,
Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like :
testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s -> (x+s, x) 0
I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ?
Bruno
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Thanks a lot, it looks exactly what I'm trying to do ! I'll test it ASAP
bruno
On 15 Jun 2016 08:35 +0200, Michael Snoyman
If I understand the question correctly, what you're saying is:
* My upstream (testC) is both returning a result _and_ yielding a stream of values downstream * My downstream (CL.consume) is collecting those values and returning a result based on them * How can I capture both the upstream and downstream results?
If so, this is the section of the docs with the relevant functions[1]. It provides a few different fusion functions to combine an upstream and downstream without throwing away the upstream result (which is the default behavior of conduit, for various design and usability reasons). In your case, this may look something like:
runConduit (fuseBoth testC CL.consume)
Michael
[1]https://s3.amazonaws.com/haddock.stackage.org/lts-6.3/conduit-1.2.6.6/Data-C...
On Wed, Jun 15, 2016 at 8:53 AM,
wrote: Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like :
testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s ->(x+s, x) 0
I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ?
Bruno
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org(mailto:Haskell-Cafe@haskell.org) http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Well that was exacly what I needed, thanks a lot !
I still have to understand exactly why ;-)
bruno
On 15 Jun 2016 08:35 +0200, Michael Snoyman
If I understand the question correctly, what you're saying is:
* My upstream (testC) is both returning a result _and_ yielding a stream of values downstream * My downstream (CL.consume) is collecting those values and returning a result based on them * How can I capture both the upstream and downstream results?
If so, this is the section of the docs with the relevant functions[1]. It provides a few different fusion functions to combine an upstream and downstream without throwing away the upstream result (which is the default behavior of conduit, for various design and usability reasons). In your case, this may look something like:
runConduit (fuseBoth testC CL.consume)
Michael
[1]https://s3.amazonaws.com/haddock.stackage.org/lts-6.3/conduit-1.2.6.6/Data-C...
On Wed, Jun 15, 2016 at 8:53 AM,
wrote: Hello, I'm trying to use Data.Conduit, but I get stuck with mapAccum as how to get and retrieve the result. If I use it, I get a simple conduit like :
testC :: ConduitM () Int IO Int testC = Src =$= cdt where src = CL.sourceList [1..10] cdt = CL.mapAccum (\x s ->(x+s, x) 0
I can get the output with testC $$ CL.consume but how do I retrieve the accumulated sum ?
Bruno
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org(mailto:Haskell-Cafe@haskell.org) http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (3)
-
Baojun Wang
-
bruno@ruomad.net
-
Michael Snoyman