on master help sign in
Make refold signature similar to concatMap
c3ef013Harendra Kumar
core/src/Streamly/Internal/Data/Fold/Type.hs+8−6
@@ -380,10 +380,10 @@ module Streamly.Internal.Data.Fold.Type
380 , chunksOf
380 , chunksOf
381 , refoldMany
381 , refoldMany
382 , refoldMany1
382 , refoldMany1
383− , refold
384
383
385 -- ** Nesting
384 -- ** Nesting
386 , concatMap
385 , concatMap
386+ , refold
387
387
388 -- * Running A Fold
388 -- * Running A Fold
389 , initialize
389 , initialize
@@ -1048,8 +1048,6 @@ data ConcatMapState m sa a c
1048 = B !sa
1048 = B !sa
1049 | forall s. C (s -> a -> m (Step s c)) !s (s -> m c)
1049 | forall s. C (s -> a -> m (Step s c)) !s (s -> m c)
1050
1050
1051−-- Compare with foldIterate.
1052−--
1053-- | Map a 'Fold' returning function on the result of a 'Fold' and run the
1051-- | Map a 'Fold' returning function on the result of a 'Fold' and run the
1054-- returned fold. This operation can be used to express data dependencies
1052-- returned fold. This operation can be used to express data dependencies
1055-- between fold operations.
1053-- between fold operations.
@@ -1063,9 +1061,11 @@ data ConcatMapState m sa a c
1063-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
1061-- >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
1064-- 45
1062-- 45
1065--
1063--
1064+-- This does not fuse completely, see 'refold' for a fusible alternative.
1065+--
1066-- /Time: O(n^2) where @n@ is the number of compositions./
1066-- /Time: O(n^2) where @n@ is the number of compositions./
1067--
1067--
1068−-- See also: 'Streamly.Internal.Data.Stream.IsStream.foldIterateM'
1068+-- See also: 'Streamly.Internal.Data.Stream.IsStream.foldIterateM', 'refold'
1069--
1069--
1070-- @since 0.8.0
1070-- @since 0.8.0
1071--
1071--
@@ -1539,7 +1539,9 @@ refoldMany1 (Refold sstep sinject sextract) (Fold cstep cinitial cextract) =
1539
1539
1540-- | Extract the output of a fold and refold it using a 'Refold'.
1540-- | Extract the output of a fold and refold it using a 'Refold'.
1541--
1541--
1542+-- A fusible alternative to 'concatMap'.
1543+--
1542-- /Internal/
1544-- /Internal/
1543{-# INLINE refold #-}
1545{-# INLINE refold #-}
1544−refold :: Monad m => Fold m a b -> Refold m b a b -> Fold m a b
1546+refold :: Monad m => Refold m b a c -> Fold m a b -> Fold m a c
1545−refold f (Refold step inject extract) = Fold step (finish f >>= inject) extract
1547+refold (Refold step inject extract) f = Fold step (finish f >>= inject) extract