tubes- Write stream processing computations with side effects in a series of tubes.

Safe HaskellTrustworthy




newtype Source m a Source

An exhaustible source of values parameterized over a base monad. It never awaits, it only yields.

Sources are monad transformers in their own right, as they are possibly finite. They may also be synchronously merged:

    src1 :: Source IO String
    src1 = Source $ each ["line A1", "line A2", "line A3"]

    src2 :: Source IO String
    src2 = Source $ each ["line B1", "line B2", "line B3", "line B4"]

    src3 :: Source IO String
    src3 = src1 merge src2

    main :: IO ()
    main = runTube $ sample src3 >< pour display
    -- line A1
    -- line B1
    -- line A2
    -- line B2
    -- line A3
    -- line B3
    -- line B4

If one source runs out, the other will continue until completion.

Digression: originally merge was the implementation for mappend and '(<>)'. However because Source is ultimately a list transformer I thought it better that these instances preserve the behavior found in lists and instead provide a separate function for synchronous merging.




sample :: Tube () a m ()


MonadTrans Source Source 
Monad m => Monad (Source m) Source 
Monad m => Functor (Source m) Source 
Monad m => Applicative (Source m) Source 
Monad m => Alternative (Source m) Source 
Monad m => MonadPlus (Source m) Source 
MonadIO m => MonadIO (Source m) Source 
(Monad m, Floating a) => Floating (Source m a) Source 
(Monad m, Fractional a) => Fractional (Source m a) Source 
(Monad m, Num a) => Num (Source m a) Source 
Monad m => Monoid (Source m a) Source 
Monad m => Semigroup (Source m a) Source 

reduce :: Monad m => (b -> a -> b) -> b -> Tube () a m () -> m b Source

Strict left-fold of a Source, using a Pump internally.

merge :: Monad m => Source m a -> Source m a -> Source m a Source

Interleave the values of two Sources until both are exhausted.