@@ -789,10 +789,9 @@ instance Monad m => Monad (Stream m) where
789{-# ANN type FoldMany Fuse #-}
789{-# ANN type FoldMany Fuse #-}
790data FoldMany s fs b a
790data FoldMany s fs b a
791 = FoldManyStart s
791 = FoldManyStart s
792− | FoldManyConsume s fs a
792+ | FoldManyLoop s fs
793− | FoldManyBuffer s fs
794 | FoldManyYield b (FoldMany s fs b a)
793 | FoldManyYield b (FoldMany s fs b a)
795− | FoldManyFinish
794+ | FoldManyDone
797-- | This is the stream equivalent of "Data.Fold.Internal.many". The fold
796-- | This is the stream equivalent of "Data.Fold.Internal.many". The fold
798-- may consume 0 or more elements. It means:
797-- may consume 0 or more elements. It means:
@@ -810,6 +809,15 @@ foldMany (Fold fstep initial extract) (Stream step state) =
812+ {-# INLINE consume #-}
818+ FL.Done b -> FoldManyYield b (FoldManyStart s)
819+ FL.Partial ps -> FoldManyLoop s ps
813 {-# INLINE_LATE step' #-}
821 {-# INLINE_LATE step' #-}
814 step' _ (FoldManyStart st) = do
822 step' _ (FoldManyStart st) = do
815 r <- initial
823 r <- initial
@@ -817,26 +825,17 @@ foldMany (Fold fstep initial extract) (Stream step state) =
818 $ case r of
826 $ case r of
819 FL.Done b -> FoldManyYield b (FoldManyStart st)
827 FL.Done b -> FoldManyYield b (FoldManyStart st)
820− FL.Partial fs -> FoldManyBuffer st fs
828+ FL.Partial fs -> FoldManyLoop st fs
821− -- This state is not strictly required but it helps the compiler fuse the
823− step' _ (FoldManyConsume st fs x) = do
828− FL.Done b -> FoldManyYield b (FoldManyStart st)
829− FL.Partial fs1 -> FoldManyBuffer st fs1
830− step' gst (FoldManyBuffer st fs) = do
829+ step' gst (FoldManyLoop st fs) = do
831 r <- step (adaptState gst) st
830 r <- step (adaptState gst) st
832 case r of
831 case r of
833− Yield x s -> return $ Skip $ FoldManyConsume s fs x
832+ Yield x s -> consume x s fs
834− Skip s -> return $ Skip (FoldManyBuffer s fs)
833+ Skip s -> return $ Skip (FoldManyLoop s fs)
835 Stop -> do
834 Stop -> do
836 b <- extract fs
835 b <- extract fs
837− return $ Skip (FoldManyYield b FoldManyFinish)
836+ return $ Skip (FoldManyYield b FoldManyDone)
838 step' _ (FoldManyYield b next) = return $ Yield b next
837 step' _ (FoldManyYield b next) = return $ Yield b next
839− step' _ FoldManyFinish = return Stop
838+ step' _ FoldManyDone = return Stop
841{-# ANN type FoldMany1 Fuse #-}
840{-# ANN type FoldMany1 Fuse #-}
842data FoldMany1 s fs b a
841data FoldMany1 s fs b a