Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Documentation
An exhaustible source of values parameterized over a base monad. It never
await
s, it only yield
s.
Source
s 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.
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 |