@@ -53,7 +53,7 @@ module Streamly.Prelude
5353 -- * Special Generation
5454 -- | Generate a monadic stream from an input structure, a seed or a
5555 -- generation function.
56− , once
56+ , K.yieldM
5757 , replicateM
5858 , repeatM
5959 , iterate
@@ -121,6 +121,7 @@ module Streamly.Prelude
121121 , toHandle
122122
123123 -- * Deprecated
124+ , once
124125 , each
125126 , scan
126127 , foldl
@@ -217,7 +218,7 @@ unfoldrM step = go
217218 case mayb of
218219 Nothing -> stp
219220 Just (a, b) ->
220− K.runStream (toStream (return a |: go b)) svr stp sng yld
221+ K.unStream (toStream (return a |: go b)) svr stp sng yld
221222
222223-- | Construct a stream from a 'Foldable' containing pure values.
223224--
@@ -310,7 +311,7 @@ iterateM step = go
310311 where
311312 go s = fromStream $ K.Stream $ \svr stp sng yld -> do
312313 next <- step s
313− K.runStream (toStream (return s |: go next)) svr stp sng yld
314+ K.unStream (toStream (return s |: go next)) svr stp sng yld
314315
315316-- | Read lines from an IO Handle into a stream of Strings.
316317--
@@ -344,8 +345,8 @@ foldr step acc m = go (toStream m)
344345 go m1 =
345346 let stop = return acc
346347 single a = return (step a acc)
347− yield a r = go r >>= \b -> return (step a b)
348− in (K.runStream m1) Nothing stop single yield
348+ yieldk a r = go r >>= \b -> return (step a b)
349+ in (K.unStream m1) Nothing stop single yieldk
349350
350351-- | Lazy right fold with a monadic step function. For example, to fold a
351352-- stream into a list:
@@ -363,8 +364,8 @@ foldrM step acc m = go (toStream m)
363364 go m1 =
364365 let stop = return acc
365366 single a = step a acc
366− yield a r = go r >>= step a
367− in (K.runStream m1) Nothing stop single yield
367+ yieldk a r = go r >>= step a
368+ in (K.unStream m1) Nothing stop single yieldk
368369
369370-- | Strict left scan with an extraction function. Like 'scanl'', but applies a
370371-- user supplied extraction function (the third argument) at each step. This is
@@ -379,10 +380,10 @@ scanx step begin done m =
379380 where
380381 go m1 !acc = K.Stream $ \_ stp sng yld ->
381382 let single a = sng (done $ step acc a)
382− yield a r =
383+ yieldk a r =
383384 let s = step acc a
384385 in yld (done s) (go r s)
385− in K.runStream m1 Nothing stp single yield
386+ in K.unStream m1 Nothing stp single yieldk
386387
387388-- |
388389-- @since 0.1.1
@@ -413,7 +414,7 @@ foldx step begin done m = get $ go (toStream m) begin
413414 {-# NOINLINE get #-}
414415 get m1 =
415416 let single = return . done
416− in (K.runStream m1) Nothing undefined single undefined
417+ in (K.unStream m1) Nothing undefined single undefined
417418
418419 -- Note, this can be implemented by making a recursive call to "go",
419420 -- however that is more expensive because of unnecessary recursion
@@ -422,10 +423,10 @@ foldx step begin done m = get $ go (toStream m) begin
422423 go m1 !acc = K.Stream $ \_ _ sng yld ->
423424 let stop = sng acc
424425 single a = sng $ step acc a
425− yield a r =
426+ yieldk a r =
426427 let stream = go r (step acc a)
427− in (K.runStream stream) Nothing undefined sng yld
428− in (K.runStream m1) Nothing stop single yield
428+ in (K.unStream stream) Nothing undefined sng yld
429+ in (K.unStream m1) Nothing stop single yieldk
429430
430431-- |
431432-- @since 0.1.0
@@ -450,8 +451,8 @@ foldxM step begin done m = go begin (toStream m)
450451 go !acc m1 =
451452 let stop = acc >>= done
452453 single a = acc >>= \b -> step b a >>= done
453− yield a r = acc >>= \b -> go (step b a) r
454− in (K.runStream m1) Nothing stop single yield
454+ yieldk a r = acc >>= \b -> go (step b a) r
455+ in (K.unStream m1) Nothing stop single yieldk
455456
456457-- |
457458-- @since 0.1.0
@@ -474,8 +475,8 @@ uncons :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (a, t m a))
474475uncons m =
475476 let stop = return Nothing
476477 single a = return (Just (a, nil))
477− yield a r = return (Just (a, fromStream r))
478− in (K.runStream (toStream m)) Nothing stop single yield
478+ yieldk a r = return (Just (a, fromStream r))
479+ in (K.unStream (toStream m)) Nothing stop single yieldk
479480
480481-- | Write a stream of Strings to an IO Handle.
481482--
@@ -486,8 +487,8 @@ toHandle h m = go (toStream m)
486487 go m1 =
487488 let stop = return ()
488489 single a = liftIO (IO.hPutStrLn h a)
489− yield a r = liftIO (IO.hPutStrLn h a) >> go r
490− in (K.runStream m1) Nothing stop single yield
490+ yieldk a r = liftIO (IO.hPutStrLn h a) >> go r
491+ in (K.unStream m1) Nothing stop single yieldk
491492
492493------------------------------------------------------------------------------
493494-- Special folds
@@ -508,8 +509,8 @@ take :: IsStream t => Int -> t m a -> t m a
508509take n m = fromStream $ go n (toStream m)
509510 where
510511 go n1 m1 = K.Stream $ \_ stp sng yld ->
511− let yield a r = yld a (go (n1 - 1) r)
512− in if n1 <= 0 then stp else (K.runStream m1) Nothing stp sng yield
512+ let yieldk a r = yld a (go (n1 - 1) r)
513+ in if n1 <= 0 then stp else (K.unStream m1) Nothing stp sng yieldk
513514
514515-- | Include only those elements that pass a predicate.
515516--
@@ -521,9 +522,9 @@ filter p m = fromStream $ go (toStream m)
521522 go m1 = K.Stream $ \_ stp sng yld ->
522523 let single a | p a = sng a
523524 | otherwise = stp
524− yield a r | p a = yld a (go r)
525− | otherwise = (K.runStream r) Nothing stp single yield
526− in (K.runStream m1) Nothing stp single yield
525+ yieldk a r | p a = yld a (go r)
526+ | otherwise = (K.unStream r) Nothing stp single yieldk
527+ in (K.unStream m1) Nothing stp single yieldk
527528
528529-- | End the stream as soon as the predicate fails on an element.
529530--
@@ -535,9 +536,9 @@ takeWhile p m = fromStream $ go (toStream m)
535536 go m1 = K.Stream $ \_ stp sng yld ->
536537 let single a | p a = sng a
537538 | otherwise = stp
538− yield a r | p a = yld a (go r)
539+ yieldk a r | p a = yld a (go r)
539540 | otherwise = stp
540− in (K.runStream m1) Nothing stp single yield
541+ in (K.unStream m1) Nothing stp single yieldk
541542
542543-- | Discard first 'n' elements from the stream and take the rest.
543544--
@@ -547,11 +548,11 @@ drop n m = fromStream $ go n (toStream m)
547548 where
548549 go n1 m1 = K.Stream $ \_ stp sng yld ->
549550 let single _ = stp
550− yield _ r = (K.runStream $ go (n1 - 1) r) Nothing stp sng yld
551+ yieldk _ r = (K.unStream $ go (n1 - 1) r) Nothing stp sng yld
551552 -- Somehow "<=" check performs better than a ">"
552553 in if n1 <= 0
553− then (K.runStream m1) Nothing stp sng yld
554− else (K.runStream m1) Nothing stp single yield
554+ then (K.unStream m1) Nothing stp sng yld
555+ else (K.unStream m1) Nothing stp single yieldk
555556
556557-- | Drop elements in the stream as long as the predicate succeeds and then
557558-- take the rest of the stream.
@@ -564,9 +565,9 @@ dropWhile p m = fromStream $ go (toStream m)
564565 go m1 = K.Stream $ \_ stp sng yld ->
565566 let single a | p a = stp
566567 | otherwise = sng a
567− yield a r | p a = (K.runStream r) Nothing stp single yield
568+ yieldk a r | p a = (K.unStream r) Nothing stp single yieldk
568569 | otherwise = yld a r
569− in (K.runStream m1) Nothing stp single yield
570+ in (K.unStream m1) Nothing stp single yieldk
570571
571572-- | Determine whether all elements of a stream satisfy a predicate.
572573--
@@ -577,9 +578,9 @@ all p m = go (toStream m)
577578 go m1 =
578579 let single a | p a = return True
579580 | otherwise = return False
580− yield a r | p a = go r
581+ yieldk a r | p a = go r
581582 | otherwise = return False
582− in (K.runStream m1) Nothing (return True) single yield
583+ in (K.unStream m1) Nothing (return True) single yieldk
583584
584585-- | Determine whether any of the elements of a stream satisfy a predicate.
585586--
@@ -590,9 +591,9 @@ any p m = go (toStream m)
590591 go m1 =
591592 let single a | p a = return True
592593 | otherwise = return False
593− yield a r | p a = return True
594+ yieldk a r | p a = return True
594595 | otherwise = go r
595− in (K.runStream m1) Nothing (return False) single yield
596+ in (K.unStream m1) Nothing (return False) single yieldk
596597
597598-- | Determine the sum of all elements of a stream of numbers
598599--
@@ -613,8 +614,8 @@ head :: Monad m => SerialT m a -> m (Maybe a)
613614head m =
614615 let stop = return Nothing
615616 single a = return (Just a)
616− yield a _ = return (Just a)
617− in (K.runStream (toStream m)) Nothing stop single yield
617+ yieldk a _ = return (Just a)
618+ in (K.unStream (toStream m)) Nothing stop single yieldk
618619
619620-- | Extract all but the first element of the stream, if any.
620621--
@@ -623,8 +624,8 @@ tail :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
623624tail m =
624625 let stop = return Nothing
625626 single _ = return $ Just nil
626− yield _ r = return $ Just $ fromStream r
627− in (K.runStream (toStream m)) Nothing stop single yield
627+ yieldk _ r = return $ Just $ fromStream r
628+ in (K.unStream (toStream m)) Nothing stop single yieldk
628629
629630-- | Extract the last element of the stream, if any.
630631--
@@ -640,8 +641,8 @@ null :: Monad m => SerialT m a -> m Bool
640641null m =
641642 let stop = return True
642643 single _ = return False
643− yield _ _ = return False
644− in (K.runStream (toStream m)) Nothing stop single yield
644+ yieldk _ _ = return False
645+ in (K.unStream (toStream m)) Nothing stop single yieldk
645646
646647-- | Determine whether an element is present in the stream.
647648--
@@ -652,8 +653,8 @@ elem e m = go (toStream m)
652653 go m1 =
653654 let stop = return False
654655 single a = return (a == e)
655− yield a r = if a == e then return True else go r
656− in (K.runStream m1) Nothing stop single yield
656+ yieldk a r = if a == e then return True else go r
657+ in (K.unStream m1) Nothing stop single yieldk
657658
658659-- | Determine whether an element is not present in the stream.
659660--
@@ -664,8 +665,8 @@ notElem e m = go (toStream m)
664665 go m1 =
665666 let stop = return True
666667 single a = return (a /= e)
667− yield a r = if a == e then return False else go r
668− in (K.runStream m1) Nothing stop single yield
668+ yieldk a r = if a == e then return False else go r
669+ in (K.unStream m1) Nothing stop single yieldk
669670
670671-- | Determine the length of the stream.
671672--
@@ -681,11 +682,11 @@ reverse :: (IsStream t) => t m a -> t m a
681682reverse m = fromStream $ go K.nil (toStream m)
682683 where
683684 go rev rest = K.Stream $ \_ stp sng yld ->
684− let runIt x = K.runStream x Nothing stp sng yld
685+ let runIt x = K.unStream x Nothing stp sng yld
685686 stop = runIt rev
686687 single a = runIt $ a `K.cons` rev
687− yield a r = runIt $ go (a `K.cons` rev) r
688− in K.runStream rest Nothing stop single yield
688+ yieldk a r = runIt $ go (a `K.cons` rev) r
689+ in K.unStream rest Nothing stop single yieldk
689690
690691-- XXX replace the recursive "go" with continuation
691692-- | Determine the minimum element in a stream.
@@ -697,8 +698,8 @@ minimum m = go Nothing (toStream m)
697698 go res m1 =
698699 let stop = return res
699700 single a = return $ min_ a res
700− yield a r = go (min_ a res) r
701− in (K.runStream m1) Nothing stop single yield
701+ yieldk a r = go (min_ a res) r
702+ in (K.unStream m1) Nothing stop single yieldk
702703
703704 min_ a res = case res of
704705 Nothing -> Just a
@@ -714,8 +715,8 @@ maximum m = go Nothing (toStream m)
714715 go res m1 =
715716 let stop = return res
716717 single a = return $ max_ a res
717− yield a r = go (max_ a res) r
718− in (K.runStream m1) Nothing stop single yield
718+ yieldk a r = go (max_ a res) r
719+ in (K.unStream m1) Nothing stop single yieldk
719720
720721 max_ a res = case res of
721722 Nothing -> Just a
@@ -745,8 +746,8 @@ mapM f m = go (toStream m)
745746 where
746747 go m1 = fromStream $ K.Stream $ \svr stp sng yld ->
747748 let single a = f a >>= sng
748− yield a r = K.runStream (toStream (f a |: (go r))) svr stp sng yld
749− in (K.runStream m1) Nothing stp single yield
749+ yieldk a r = K.unStream (toStream (f a |: (go r))) svr stp sng yld
750+ in (K.unStream m1) Nothing stp single yieldk
750751
751752-- | Map a 'Maybe' returning function to a stream, filter out the 'Nothing'
752753-- elements, and return a stream of values extracted from 'Just'.
@@ -760,10 +761,10 @@ mapMaybe f m = go (toStream m)
760761 let single a = case f a of
761762 Just b -> sng b
762763 Nothing -> stp
763− yield a r = case f a of
764+ yieldk a r = case f a of
764765 Just b -> yld b (toStream $ go r)
765− Nothing -> (K.runStream r) Nothing stp single yield
766− in (K.runStream m1) Nothing stp single yield
766+ Nothing -> (K.unStream r) Nothing stp single yieldk
767+ in (K.unStream m1) Nothing stp single yieldk
767768
768769-- | Like 'mapMaybe' but maps a monadic function.
769770--
@@ -786,8 +787,8 @@ mapM_ f m = go (toStream m)
786787 go m1 =
787788 let stop = return ()
788789 single a = void (f a)
789− yield a r = f a >> go r
790− in (K.runStream m1) Nothing stop single yield
790+ yieldk a r = f a >> go r
791+ in (K.unStream m1) Nothing stop single yieldk
791792
792793-- | Reduce a stream of monadic actions to a stream of the output of those
793794-- actions.
@@ -808,5 +809,5 @@ sequence m = go (toStream m)
808809 where
809810 go m1 = fromStream $ K.Stream $ \svr stp sng yld ->
810811 let single ma = ma >>= sng
811− yield ma r = K.runStream (toStream $ ma |: go r) svr stp sng yld
812− in (K.runStream m1) Nothing stp single yield
812+ yieldk ma r = K.unStream (toStream $ ma |: go r) svr stp sng yld
813+ in (K.unStream m1) Nothing stp single yieldk