emit package:box
Hook a committer action to a queue, creating an emitter continuation.
Emitter wraps a producer destructor.
"Every Thought emits a Dice Throw" ~ Stéphane Mallarmé
An
Emitter emits values of type
Maybe a. Source
and producer are similar metaphors. An Emitter reaches into itself for
the value to emit, where itself is an opaque thing from the pov of
usage.
>>> e = Emitter (pure (Just "I'm emitted"))
>>> emit e
Just "I'm emitted"
>>> emit mempty
Nothing
queue a stateful emitter, supplying initial state
>>> import Control.Monad.State.Lazy
>>> toListM <$|> (evalEmitter 0 <$> takeE 4 =<< qList [0..])
[0,1,2,3]
queue a stateful emitter, supplying initial state
Glues an emitter to a committer, then resupplies the emitter.
>>> (c1,l1) <- refCommitter :: IO (Committer IO Int, IO [Int])
>>> close $ toListM <$> (forkEmit <$> (qList [1..3]) <*> pure c1)
[1,2,3]
>>> l1
[1,2,3]
Emit from a list IORef
>>> e <- refEmitter [1..3]
>>> toListM e
[1,2,3]