on master help sign in
Make refold signature similar to concatMap
commitc3ef01328e037a3466512a2bd96c2ddb4d02721e authorHarendra Kumar <harendra@composewell.com> dateWed 30 Mar 2022, 22:58 (5 years ago) parentd1b678f
1 file changed+8−6
core/src/Streamly/Internal/Data/Fold/Type.hs+8−6
core/src/Streamly/Internal/Data/Fold/Type.hs+8−6
@@ -380,10 +380,10 @@ module Streamly.Internal.Data.Fold.Type
380380 , chunksOf
381381 , refoldMany
382382 , refoldMany1
383− , refold
384383
385384 -- ** Nesting
386385 , concatMap
386+ , refold
387387
388388 -- * Running A Fold
389389 , initialize
@@ -1048,8 +1048,6 @@ data ConcatMapState m sa a c
10481048 = B !sa
10491049 | forall s. C (s -> a -> m (Step s c)) !s (s -> m c)
10501050
1051−-- Compare with foldIterate.
1052−--
10531051-- | Map a 'Fold' returning function on the result of a 'Fold' and run the
10541052-- returned fold. This operation can be used to express data dependencies
10551053-- between fold operations.
@@ -1063,9 +1061,11 @@ data ConcatMapState m sa a c
10631061-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
10641062-- 45
10651063--
1064+-- This does not fuse completely, see 'refold' for a fusible alternative.
1065+--
10661066-- /Time: O(n^2) where @n@ is the number of compositions./
10671067--
1068−-- See also: 'Streamly.Internal.Data.Stream.IsStream.foldIterateM'
1068+-- See also: 'Streamly.Internal.Data.Stream.IsStream.foldIterateM', 'refold'
10691069--
10701070-- @since 0.8.0
10711071--
@@ -1539,7 +1539,9 @@ refoldMany1 (Refold sstep sinject sextract) (Fold cstep cinitial cextract) =
15391539
15401540-- | Extract the output of a fold and refold it using a 'Refold'.
15411541--
1542+-- A fusible alternative to 'concatMap'.
1543+--
15421544-- /Internal/
15431545{-# INLINE refold #-}
1544−refold :: Monad m => Fold m a b -> Refold m b a b -> Fold m a b
1545−refold f (Refold step inject extract) = Fold step (finish f >>= inject) extract
1546+refold :: Monad m => Refold m b a c -> Fold m a b -> Fold m a c
1547+refold (Refold step inject extract) f = Fold step (finish f >>= inject) extract