bluefin-0.4.0.1: The Bluefin effect system
Safe HaskellNone
LanguageHaskell2010

Bluefin.Coroutine

Synopsis

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 much yet. You might want to start with Bluefin.Stream, which is the most common way to use coroutines.

Prompt finalization/resource safety

Bluefin Stream/Consume/Coroutine computations have much better resource safety properties than Conduit and Pipes. You can use Bluefin.Eff.bracket within a streaming computation and the acquired resource is guaranteed to be released and the end of the bracket, rather than at the end of the ResourceT scope as it is the case in Conduit and Pipes. See the blog post Bluefin streams finalize promptly for more details.

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.

Instances

Instances details
e :> es => OneWayCoercible (Coroutine a b e :: Type) (Coroutine a b es :: Type) 
Instance details

Defined in Bluefin.Internal

Handle (Coroutine a b) 
Instance details

Defined in Bluefin.Internal

Methods

handleImpl :: HandleD (Coroutine a b) #

(TypeError ('Text "Coroutine cannot be cloned. Perhaps you want an STM channel?") :: Constraint) => CloneableHandle (Coroutine a b) 
Instance details

Defined in Bluefin.Internal.CloneableHandle

Handlers

forEach #

Arguments

:: 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 

Apply an effectful function to each element yielded to the stream.

>>> 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], ())

connectCoroutines #

Arguments

:: 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 as and bs. When the first yields its first a it starts the second (which is awaiting an a).

Effectful operations

yieldCoroutine #

Arguments

:: forall (e1 :: Effects) (es :: Effects) a b. e1 :> es 
=> Coroutine a b e1 
-> a

͘

-> Eff es b