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
- onState :: MonadState s m => (s -> m ()) -> Pipe a a m r
- delay :: MonadIO io => Int -> Pipe a a io ()
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.
retrieve :: MonadState s m => Getter s b -> Pipe a (b, a) m r Source #
Yields a view into the stored value.
locally :: Monad m => (s -> a) -> (b -> s -> t) -> Pipe a b m r -> Pipe s t m r Source #
Run a pipe in a larger stream, using view function and modify function of the larger stream.
onState :: MonadState s m => (s -> m ()) -> Pipe a a m r Source #
Do something with the state everytime there is a yield.