Safe Haskell | None |
---|---|
Language | Haskell2010 |
Miscellaneous utilities for pipes, required by glazier-tutorial
- fromInputSTM :: Input a -> Producer' a STM ()
- toOutputSTM :: Output a -> Consumer' a STM ()
- batch :: Input a -> Input (NonEmpty a)
- buffer :: Monad m => Int -> [a] -> Pipe a [a] m r
- store :: MonadState s m => Getter a b -> Setter' s b -> Pipe a a m r
- retrieve :: MonadState s m => Getter s b -> Pipe a (b, a) m r
- locally :: Monad m => (s -> a) -> (b -> s -> t) -> Pipe a b m r -> Pipe s t m r
Documentation
fromInputSTM :: Input a -> Producer' a STM () Source #
Like Pipes.Concurrent.fromInput, but stays in STM.
Using hoist atomically
to convert to IO monad seems to work.
Do not use unsafeHoist atomically
.
toOutputSTM :: Output a -> Consumer' a STM () Source #
Like Pipes.Concurrent.toOutput, but stays in STM.
Using hoist atomically
to convert to IO monad seems to work.
Do not use unsafeHoist atomically
.
batch :: Input a -> Input (NonEmpty a) Source #
Reads as much as possible from an input and return a list of all unblocked values read. Blocks if the first value read is blocked.
buffer :: Monad m => Int -> [a] -> Pipe a [a] m r Source #
Given a size and a initial tail, create a pipe that
will buffer the output of a producer.
This pipe is stateful, and will only buffer until the immediate connecting
producer is finished.
forever $ do
a <- await
yield a >-> buffer 2 [] -- will only ever result a producer of single 'a : []'.
(forever $ do
a <- await
yield a
) >-> buffer 2 [] -- will buffer properly and produce '[latest, old]'
store :: MonadState s m => Getter a b -> Setter' s b -> Pipe a a m r Source #
Store the output of the pipe into a MonadState.