on master help sign in
Init the fold without first input in foldMany
38dda06Harendra Kumar
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+21−17
@@ -1785,7 +1785,7 @@ foldManyPost (Fold fstep initial extract) (Stream step state) =
1785{-# ANN type FoldMany Fuse #-}
1785{-# ANN type FoldMany Fuse #-}
1786data FoldMany s fs b a
1786data FoldMany s fs b a
1787 = FoldManyStart s
1787 = FoldManyStart s
1788− | FoldManyFirst a s
1788+ | FoldManyFirst fs s
1789 | FoldManyLoop s fs
1789 | FoldManyLoop s fs
1790 | FoldManyYield b (FoldMany s fs b a)
1790 | FoldManyYield b (FoldMany s fs b a)
1791 | FoldManyDone
1791 | FoldManyDone
@@ -1836,17 +1836,19 @@ foldMany (Fold fstep initial extract) (Stream step state) =
1836 FL.Partial ps -> FoldManyLoop s ps
1836 FL.Partial ps -> FoldManyLoop s ps
1837
1837
1838 {-# INLINE_LATE step' #-}
1838 {-# 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
1840 r <- step (adaptState gst) st
1847 r <- step (adaptState gst) st
1841 case r of
1848 case r of
1849+ Yield x s -> consume x s fs
1842− Yield x s -> return $ Skip (FoldManyFirst x s)
1850+ Skip s -> return $ Skip (FoldManyFirst fs s)
1843− Skip s -> return $ Skip (FoldManyStart s)
1844 Stop -> return Stop
1851 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
1850 step' gst (FoldManyLoop st fs) = do
1852 step' gst (FoldManyLoop st fs) = do
1851 r <- step (adaptState gst) st
1853 r <- step (adaptState gst) st
1852 case r of
1854 case r of
@@ -1885,17 +1887,19 @@ refoldMany (Refold fstep inject extract) action (Stream step state) =
1885 FL.Partial ps -> FoldManyLoop s ps
1887 FL.Partial ps -> FoldManyLoop s ps
1886
1888
1887 {-# INLINE_LATE step' #-}
1889 {-# 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
1889 r <- step (adaptState gst) st
1898 r <- step (adaptState gst) st
1890 case r of
1899 case r of
1900+ Yield x s -> consume x s fs
1891− Yield x s -> return $ Skip (FoldManyFirst x s)
1901+ Skip s -> return $ Skip (FoldManyFirst fs s)
1892− Skip s -> return $ Skip (FoldManyStart s)
1893 Stop -> return Stop
1902 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
1899 step' gst (FoldManyLoop st fs) = do
1903 step' gst (FoldManyLoop st fs) = do
1900 r <- step (adaptState gst) st
1904 r <- step (adaptState gst) st
1901 case r of
1905 case r of