Marronnier
Marronnier

Reputation: 399

Conduit weird behavior

I'm new to Haskell Conduit and I'm learning how to use it. I encountered a weird behevior.

Here, we have:

#!/usr/bin/env stack
-- stack --resolver lts-10.9 script

import Conduit

main :: IO ()
main = runConduit
  $ yieldMany [1..10::Int]
 .| do
      mapC id .| (await >>= maybe (return ()) leftover)
      printC
 .| do
      leftover "Hello There!"
      printC

and the result is:

$ ./Example21.hs
"Hello There!"
2
3
4
5
6
7
8
9
10

I don't understand why 1 isn't printed.

Upvotes: 2

Views: 71

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31305

This is the behavior of leftovers. Leftovers cannot propagate from outside of the .| fusion operator. As the Haddocks say:

Leftover data returned from the right Conduit will be discarded.

You can use the fusion with leftovers functions if you need to recover the leftovers.

Upvotes: 2

Related Questions