I have a conduit pipeline whose monad includes state. At one point I'd like to have a conduit that streams the state to the following ones (this is a simplified version of what I actually need).
But I have trouble making this. The following example only streams the state once, from the yield:
import Conduit (ConduitM, yield)
import Control.Monad.Except (Except)
import Control.Monad.State.Lazy (StateT, get)
type CondState = String
type CondMonad = StateT CondState (Except String)
passState :: ConduitM i CondState CondMonad ()
passState = do
state <- get
yield state
If I run
runExcept $ (runStateT . runConduit $ yieldMany [(1::Int)..] .| passState .| sinkList) "state"
I get
Right (["state"], "state")
rather than the infinite list that I'm aiming for in the first tuple position.
In the actual application the state changes as the conduit streams.
Any ideas?