mirror of
https://github.com/tomjaguarpaw/bluefin.git
synced 2024-10-04 01:17:52 +03:00
Add withYieldToList
This commit is contained in:
parent
aa154c4bb0
commit
50bf7c9f3f
@ -777,6 +777,24 @@ yieldToList f = do
|
||||
(as, r) <- yieldToReverseList f
|
||||
pure (reverse as, r)
|
||||
|
||||
-- |
|
||||
-- @
|
||||
-- >>> runPureEff $ withYieldToList $ \y -> do
|
||||
-- yield y 1
|
||||
-- yield y 2
|
||||
-- yield y 100
|
||||
-- pure length
|
||||
-- 3
|
||||
-- @
|
||||
withYieldToList ::
|
||||
-- | Stream computation
|
||||
(forall e. Stream a e -> Eff (e :& es) ([a] -> r)) ->
|
||||
-- | Result
|
||||
Eff es r
|
||||
withYieldToList f = do
|
||||
(l, g) <- yieldToList f
|
||||
pure (g l)
|
||||
|
||||
-- | This is more efficient than 'yieldToList' because it gathers the
|
||||
-- elements into a stack in reverse order. @yieldToList@ then reverses
|
||||
-- that stack.
|
||||
|
@ -61,6 +61,13 @@ yieldExample = runPureEff $ yieldToList $ \y -> do
|
||||
yield y 2
|
||||
yield y 100
|
||||
|
||||
withYieldToListExample :: Int
|
||||
withYieldToListExample = runPureEff $ withYieldToList $ \y -> do
|
||||
yield y 1
|
||||
yield y 2
|
||||
yield y 100
|
||||
pure length
|
||||
|
||||
forEachExample :: ([Int], ())
|
||||
forEachExample = runPureEff $ yieldToList $ \y -> do
|
||||
forEach (inFoldable [0 .. 4]) $ \i -> do
|
||||
|
@ -12,6 +12,7 @@ module Bluefin.Stream
|
||||
forEach,
|
||||
yieldToList,
|
||||
yieldToReverseList,
|
||||
withYieldToList,
|
||||
enumerate,
|
||||
enumerateFrom,
|
||||
mapMaybe,
|
||||
|
Loading…
Reference in New Issue
Block a user