Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Coroutine a b (e :: Effects)
- forEach :: forall a b (es :: Effects) r. (forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) r) -> (a -> Eff es b) -> Eff es r
- connectCoroutines :: forall (es :: Effects) a b r. (forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r) -> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r) -> Eff es r
- yieldCoroutine :: forall (e1 :: Effects) (es :: Effects) a b. e1 :> es => Coroutine a b e1 -> a -> Eff es b
Documentation
Coroutine
allows to yield values and receive results back.
Wikipedia
suggests
that Bluefin's coroutines are "second-class stackful
coroutines". This module is not documented yet. You might
want to start with Bluefin.Stream, which is the most common
way to use coroutines.
Handle
data Coroutine a b (e :: Effects) #
A handle to a coroutine that yields values of type a
and then
expects values of type b
.
Handlers
:: forall a b (es :: Effects) r. (forall (e1 :: Effects). Coroutine a b e1 -> Eff (e1 :& es) r) | |
-> (a -> Eff es b) | Apply this effectful function for each element of the coroutine |
-> Eff es r |
>>> runPureEff $ yieldToList $ \y -> do forEach (inFoldable [0 .. 3]) $ \i -> do yield y i yield y (i * 10) ([0, 0, 1, 10, 2, 20, 3, 30], ())
:: forall (es :: Effects) a b r. (forall (e :: Effects). Coroutine a b e -> Eff (e :& es) r) | |
-> (forall (e :: Effects). a -> Coroutine b a e -> Eff (e :& es) r) | |
-> Eff es r | ͘ |
Connect two coroutines. Their execution is interleaved by
exchanging a
s and b
s. When the first yields its first a
it
starts the second (which is awaiting an a
).