Copyright | 2013-2021 Luis Pedro Coelho |
---|---|
License | MIT |
Maintainer | luis@luispedro.org |
Safe Haskell | None |
Language | Haskell2010 |
A few miscellaneous conduit utils
Synopsis
- awaitJust :: Monad m => (a -> ConduitT a b m ()) -> ConduitT a b m ()
- enumerateC :: Monad m => ConduitT a (Int, a) m ()
- groupC :: Monad m => Int -> ConduitT a [a] m ()
- dispatchC :: Monad m => [ConduitT a Void m r] -> ConduitT (Int, a) Void m [r]
- dispatchC_ :: Monad m => [ConduitT a Void m ()] -> ConduitT (Int, a) Void m ()
Documentation
awaitJust :: Monad m => (a -> ConduitT a b m ()) -> ConduitT a b m () Source #
Act on the next input (do nothing if no input). awaitJust f
is equivalent to
do next <- C.await case next of Just val -> f val Nothing -> return ()
This is a simple utility adapted from http://neilmitchell.blogspot.de/2015/07/thoughts-on-conduits.html
enumerateC :: Monad m => ConduitT a (Int, a) m () Source #
Conduit analogue to Python's enumerate function
groupC :: Monad m => Int -> ConduitT a [a] m () Source #
Warning: This function is deprecated; use chunksOf
This function is deprecated; use chunksOf
groupC yields the input as groups of n
elements. If the input is not a
multiple of n
, the last element will be incomplete
Example:
CC.yieldMany [0..10] .| groupC 3 .| CC.consumeList
results in [ [0,1,2], [3,4,5], [6,7,8], [9, 10] ]
dispatchC :: Monad m => [ConduitT a Void m r] -> ConduitT (Int, a) Void m [r] Source #
dispatchC dispatches indexed input to the respective sink
Example:
let input = [(0, "one") ,(1, "two") ,(0, "three") ] CC.yieldMany input .| dispatches [sink1, sink2]
Then sink1
will receive "one" and "three", while sink2
will receive "two"
Out of bounds indices are clipped to the 0..n-1 range (where n
is 'length sinks')