on master help sign in
Use Tuple'Fused in Fold.take
commit49a4333edb78804ccae8fc6b9fd7e8904c6db66e authorHarendra Kumar <harendra@composewell.com> dateFri 18 Jun 2021, 02:11 (5 years ago) parent624158d
1 file changed+8−4
src/Streamly/Internal/Data/Fold/Type.hs+8−4
src/Streamly/Internal/Data/Fold/Type.hs+8−4
@@ -970,6 +970,10 @@ catMaybes = filter isJust . map fromJust
970970-- Parsing
971971------------------------------------------------------------------------------
972972
973+-- Required to fuse "take" with "many" in "chunksOf", for ghc-9.x
974+{-# ANN type Tuple'Fused Fuse #-}
975+data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
976+
973977-- | Take at most @n@ input elements and fold them using the supplied fold. A
974978-- negative count is treated as 0.
975979--
@@ -988,22 +992,22 @@ take n (Fold fstep finitial fextract) = Fold step initial extract
988992 case res of
989993 Partial s ->
990994 if n > 0
991− then return $ Partial $ Tuple' 0 s
995+ then return $ Partial $ Tuple'Fused 0 s
992996 else Done <$> fextract s
993997 Done b -> return $ Done b
994998
995− step (Tuple' i r) a = do
999+ step (Tuple'Fused i r) a = do
9961000 res <- fstep r a
9971001 case res of
9981002 Partial sres -> do
9991003 let i1 = i + 1
1000− s1 = Tuple' i1 sres
1004+ s1 = Tuple'Fused i1 sres
10011005 if i1 < n
10021006 then return $ Partial s1
10031007 else Done <$> fextract sres
10041008 Done bres -> return $ Done bres
10051009
1006− extract (Tuple' _ r) = fextract r
1010+ extract (Tuple'Fused _ r) = fextract r
10071011
10081012------------------------------------------------------------------------------
10091013-- Nesting