| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Bluefin.Capability.Yield
Synopsis
- type Yield a = Stream a
- 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
- yieldToList :: forall a (es :: Effects) r. (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) -> Eff es ([a], r)
- yieldToReverseList :: forall a (es :: Effects) r. (forall (e :: Effects). Stream a e -> Eff (e :& es) r) -> Eff es ([a], r)
- withYieldToList :: forall a (es :: Effects) r. (forall (e :: Effects). Stream a e -> Eff (e :& es) ([a] -> r)) -> Eff es r
- ignoreYield :: forall a (es :: Effects) r. (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) -> Eff es r
- enumerate :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es => (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) -> Stream (Int, a) e2 -> Eff es r
- enumerateFrom :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es => Int -> (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) -> Stream (Int, a) e2 -> Eff es r
- mapMaybe :: forall (e2 :: Effects) (es :: Effects) a b r. e2 <: es => (a -> Maybe b) -> (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) -> Stream b e2 -> Eff es r
- catMaybes :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es => (forall (e1 :: Effects). Stream (Maybe a) e1 -> Eff (e1 :& es) r) -> Stream a e2 -> Eff es r
- awaitYield :: forall a (es :: Effects) r. (forall (e :: Effects). Await a e -> Eff (e :& es) r) -> (forall (e :: Effects). Yield a e -> Eff (e :& es) r) -> Eff es r
- yield :: forall (e1 :: Effects) (es :: Effects) a. e1 <: es => Stream a e1 -> a -> Eff es ()
- inFoldable :: forall t (e1 :: Effects) (es :: Effects) a. (Foldable t, e1 <: es) => t a -> Stream a e1 -> Eff es ()
- cycleToYield :: forall f (e1 :: Effects) (es :: Effects) a. (Foldable f, e1 <: es) => f a -> Yield a e1 -> Eff es ()
- takeAwait :: forall (e1 :: Effects) (es :: Effects) (e2 :: Effects) a. (e1 <: es, e2 <: es) => Int -> Await a e1 -> Yield a e2 -> Eff es ()
Documentation
Yield allows you to yield values during the execution of a
Bluefin operation. It provides similar functionality to
Python's yield. The handler of the Yield will either
handle each element as soon as it is yielded (for example
forEach) or gather all yielded elements into a list (for
example yieldToList).
For information about prompt finalization/resource safety when
using Bluefin Yields, see Bluefin.Capability.Request.
Capability
Capability to yield values of type a. It is implemented as a
Request capability that can yield values of
type a and then await values of type ().
Handlers
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 -> doforEach(inFoldable[0 .. 3]) $ \i -> doyieldy i yield y (i * 10) ([0, 0, 1, 10, 2, 20, 3, 30], ())
Arguments
| :: forall a (es :: Effects) r. (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) | |
| -> Eff es ([a], r) | Yielded elements and final result |
Gather all yielded elements into a list.
>>> runPureEff $ yieldToList $ \y -> do
yield y 1
yield y 2
yield y 100
([1,2,100], ())
Arguments
| :: forall a (es :: Effects) r. (forall (e :: Effects). Stream a e -> Eff (e :& es) r) | |
| -> Eff es ([a], r) | Yielded elements in reverse order, and final result |
This is more efficient than yieldToList because it gathers the
elements into a stack in reverse order. yieldToList then reverses
that stack.
>>> runPureEff $ yieldToReverseList $ \y -> do
yield y 1
yield y 2
yield y 100
([100,2,1], ())
Arguments
| :: forall a (es :: Effects) r. (forall (e :: Effects). Stream a e -> Eff (e :& es) ([a] -> r)) | Stream computation |
| -> Eff es r | Result |
>>> runPureEff $ withYieldToList $ \y -> do yield y 1 yield y 2 yield y 100 pure length 3
Arguments
| :: forall a (es :: Effects) r. (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) | |
| -> Eff es r | ͘ |
Ignore all yielded elements.
>>> runPureEff $ ignoreYield $ \y -> do
for_ [0 .. 4] $ \i -> do
yield y i
yield y (i * 10)
pure 42
42
Arguments
| :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es | |
| => (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) | ͘ |
| -> Stream (Int, a) e2 | |
| -> Eff es r |
Pair each element in the stream with an increasing index, starting from 0.
>>> runPureEff $ yieldToList $ enumerate (inFoldable ["A", "B", "C"]) ([(0, "A"), (1, "B"), (2, "C")], ())
Arguments
| :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es | |
| => Int | Initial value |
| -> (forall (e1 :: Effects). Stream a e1 -> Eff (e1 :& es) r) | |
| -> Stream (Int, a) e2 | |
| -> Eff es r |
Pair each element in the stream with an increasing index, starting from an inital value.
>>> runPureEff $ yieldToList $ enumerateFrom 1 (inFoldable ["A", "B", "C"]) ([(1, "A"), (2, "B"), (3, "C")], ())
Arguments
| :: forall (e2 :: Effects) (es :: Effects) a r. e2 <: es | |
| => (forall (e1 :: Effects). Stream (Maybe a) e1 -> Eff (e1 :& es) r) | Input stream |
| -> Stream a e2 | |
| -> Eff es r |
Remove Nothing elements from a stream.
Arguments
| :: forall a (es :: Effects) r. (forall (e :: Effects). Await a e -> Eff (e :& es) r) | Starts running first. Each |
| -> (forall (e :: Effects). Yield a e -> Eff (e :& es) r) | ... receives the value |
| -> Eff es r |
awaitYield is connectRequests
specialized to Await and Yield, which is the most common case.
Effectful operations
Arguments
| :: forall (e1 :: Effects) (es :: Effects) a. e1 <: es | |
| => Stream a e1 | |
| -> a | Yield this value from the stream |
| -> Eff es () |
Yield an element to the stream.
>>> runPureEff $ yieldToList $ \y -> do
yield y 1
yield y 2
yield y 100
([1,2,100], ())
Arguments
| :: forall t (e1 :: Effects) (es :: Effects) a. (Foldable t, e1 <: es) | |
| => t a | Yield all these values from the stream |
| -> Stream a e1 | |
| -> Eff es () |
>>> runPureEff $ yieldToList $ inFoldable [1, 2, 100] ([1, 2, 100], ())