@@ -1785,7 +1785,7 @@ foldManyPost (Fold fstep initial extract) (Stream step state) =
17851785{-# ANN type FoldMany Fuse #-}
17861786data FoldMany s fs b a
17871787 = FoldManyStart s
1788− | FoldManyFirst a s
1788+ | FoldManyFirst fs s
17891789 | FoldManyLoop s fs
17901790 | FoldManyYield b (FoldMany s fs b a)
17911791 | FoldManyDone
@@ -1836,17 +1836,19 @@ foldMany (Fold fstep initial extract) (Stream step state) =
18361836 FL.Partial ps -> FoldManyLoop s ps
18371837
18381838 {-# INLINE_LATE step' #-}
1839− step' gst (FoldManyStart st) = do
1839+ step' _ (FoldManyStart st) = do
1840+ r <- initial
1841+ return
1842+ $ Skip
1843+ $ case r of
1844+ FL.Done b -> FoldManyYield b (FoldManyStart st)
1845+ FL.Partial fs -> FoldManyFirst fs st
1846+ step' gst (FoldManyFirst fs st) = do
18401847 r <- step (adaptState gst) st
18411848 case r of
1842− Yield x s -> return $ Skip (FoldManyFirst x s)
1843− Skip s -> return $ Skip (FoldManyStart s)
1849+ Yield x s -> consume x s fs
1850+ Skip s -> return $ Skip (FoldManyFirst fs s)
18441851 Stop -> return Stop
1845− step' _ (FoldManyFirst x st) = do
1846− r <- initial
1847− case r of
1848− FL.Done b -> return $ Skip $ FoldManyYield b (FoldManyFirst x st)
1849− FL.Partial fs -> consume x st fs
18501852 step' gst (FoldManyLoop st fs) = do
18511853 r <- step (adaptState gst) st
18521854 case r of
@@ -1885,17 +1887,19 @@ refoldMany (Refold fstep inject extract) action (Stream step state) =
18851887 FL.Partial ps -> FoldManyLoop s ps
18861888
18871889 {-# INLINE_LATE step' #-}
1888− step' gst (FoldManyStart st) = do
1890+ step' _ (FoldManyStart st) = do
1891+ r <- action >>= inject
1892+ return
1893+ $ Skip
1894+ $ case r of
1895+ FL.Done b -> FoldManyYield b (FoldManyStart st)
1896+ FL.Partial fs -> FoldManyFirst fs st
1897+ step' gst (FoldManyFirst fs st) = do
18891898 r <- step (adaptState gst) st
18901899 case r of
1891− Yield x s -> return $ Skip (FoldManyFirst x s)
1892− Skip s -> return $ Skip (FoldManyStart s)
1900+ Yield x s -> consume x s fs
1901+ Skip s -> return $ Skip (FoldManyFirst fs s)
18931902 Stop -> return Stop
1894− step' _ (FoldManyFirst x st) = do
1895− r <- action >>= inject
1896− case r of
1897− FL.Done b -> return $ Skip $ FoldManyYield b (FoldManyFirst x st)
1898− FL.Partial fs -> consume x st fs
18991903 step' gst (FoldManyLoop st fs) = do
19001904 r <- step (adaptState gst) st
19011905 case r of