@@ -842,8 +842,7 @@ foldMany (Fold fstep initial extract) (Stream step state) =
842842data FoldMany1 s fs b a
843843 = FoldMany1Start s
844844 | FoldMany1First fs s
845− | FoldMany1Consume s fs a
846− | FoldMany1Gen s fs
845+ | FoldMany1Loop s fs
847846 | FoldMany1Yield b (FoldMany1 s fs b a)
848847 | FoldMany1Done
849848
@@ -870,6 +869,15 @@ foldMany1 (Fold fstep initial extract) (Stream step state) =
870869
871870 where
872871
872+ {-# INLINE consume #-}
873+ consume x s fs = do
874+ res <- fstep fs x
875+ return
876+ $ Skip
877+ $ case res of
878+ FL.Done b -> FoldMany1Yield b (FoldMany1Start s)
879+ FL.Partial ps -> FoldMany1Loop s ps
880+
873881 {-# INLINE_LATE step' #-}
874882 step' _ (FoldMany1Start st) = do
875883 r <- initial
@@ -881,22 +889,14 @@ foldMany1 (Fold fstep initial extract) (Stream step state) =
881889 step' gst (FoldMany1First fs st) = do
882890 r <- step (adaptState gst) st
883891 case r of
884− Yield x s -> do
885− return $ Skip $ FoldMany1Consume s fs x
892+ Yield x s -> consume x s fs
886893 Skip s -> return $ Skip (FoldMany1Start s)
887894 Stop -> return Stop
888− step' _ (FoldMany1Consume st fs x) = do
889− r <- fstep fs x
890− return
891− $ Skip
892− $ case r of
893− FL.Done b -> FoldMany1Yield b (FoldMany1Start st)
894− FL.Partial fs1 -> FoldMany1Gen st fs1
895− step' gst (FoldMany1Gen st fs) = do
895+ step' gst (FoldMany1Loop st fs) = do
896896 r <- step (adaptState gst) st
897897 case r of
898− Yield x s -> return $ Skip $ FoldMany1Consume s fs x
899− Skip s -> return $ Skip (FoldMany1Gen s fs)
898+ Yield x s -> consume x s fs
899+ Skip s -> return $ Skip (FoldMany1Loop s fs)
900900 Stop -> do
901901 b <- extract fs
902902 return $ Skip (FoldMany1Yield b FoldMany1Done)