@@ -22,7 +22,7 @@ module Streamly.Internal.Data.Stream.Expand
22 -- complexity (instead O(n^2) for pair wise combinators described in the
22 -- complexity (instead O(n^2) for pair wise combinators described in the
23 -- next section. These functions can be used efficiently with
23 -- next section. These functions can be used efficiently with
24 -- 'concatMapWith' et. al. combinators that combine streams in a linear
24 -- 'concatMapWith' et. al. combinators that combine streams in a linear
25− -- fashion (contrast with 'concatPairsWith' which combines streams as a
25+ -- fashion (contrast with 'mergeMapWith' which combines streams as a
26 -- binary tree).
26 -- binary tree).
@@ -30,7 +30,7 @@ module Streamly.Internal.Data.Stream.Expand
30 -- | Like the functions in the section above these functions also combine
30 -- | Like the functions in the section above these functions also combine
31 -- two streams into a single stream but when used @n@ times linearly they
31 -- two streams into a single stream but when used @n@ times linearly they
32 -- exhibit O(n^2) complexity. They are best combined in a binary tree
32 -- exhibit O(n^2) complexity. They are best combined in a binary tree
33− -- fashion using 'concatPairsWith' giving a @n * log n@ complexity. Avoid
33+ -- fashion using 'mergeMapWith' giving a @n * log n@ complexity. Avoid
34 -- using these with 'concatMapWith' when combining a large or infinite
34 -- using these with 'concatMapWith' when combining a large or infinite
35 -- number of streams.
35 -- number of streams.
@@ -104,7 +104,7 @@ module Streamly.Internal.Data.Stream.Expand
104 -- simultaneously anyway.
104 -- simultaneously anyway.
106 -- However, in cases where the merging consumes streams in a round robin
106 -- However, in cases where the merging consumes streams in a round robin
107− -- fashion, a pair wise merging using 'concatPairsWith' would be more
107+ -- fashion, a pair wise merging using 'mergeMapWith' would be more
108 -- efficient. These cases include operations like 'mergeBy' or 'zipWith'.
108 -- efficient. These cases include operations like 'mergeBy' or 'zipWith'.
110 , concatMapWith
110 , concatMapWith
@@ -114,7 +114,7 @@ module Streamly.Internal.Data.Stream.Expand
114 -- * ConcatPairsWith
114 -- * ConcatPairsWith
115 -- | See the notes about suitable merge functions in the 'concatMapWith'
115 -- | See the notes about suitable merge functions in the 'concatMapWith'
116 -- section.
116 -- section.
117− , concatPairsWith
117+ , mergeMapWith
119 -- * IterateMap
119 -- * IterateMap
120 -- | Map and flatten Trees of Streams
120 -- | Map and flatten Trees of Streams
@@ -165,7 +165,7 @@ infixr 6 `append2`
165-- 'append' when combining two fusible streams. However, it slows down
165-- 'append' when combining two fusible streams. However, it slows down
166-- quadratically with the number of streams being appended. Therefore, it is
166-- quadratically with the number of streams being appended. Therefore, it is
167-- suitable for ad-hoc append of a few streams, and should not be used with
167-- suitable for ad-hoc append of a few streams, and should not be used with
168−-- 'concatMapWith' or 'concatPairsWith'.
168+-- 'concatMapWith' or 'mergeMapWith'.
170-- /Fused/
170-- /Fused/
@@ -360,7 +360,7 @@ mergeByM f m1 m2 = fromStreamK $ K.mergeByM f (toStreamK m1) (toStreamK m2)
360-- | Like 'mergeByM' but much faster, works best when merging statically known
360-- | Like 'mergeByM' but much faster, works best when merging statically known
361-- number of streams. When merging more than two streams try to merge pairs and
361-- number of streams. When merging more than two streams try to merge pairs and
362-- pair of pairs in a tree like structure.'mergeByM' works better with variable
362-- pair of pairs in a tree like structure.'mergeByM' works better with variable
363−-- number of streams being merged using 'concatPairsWith'.
363+-- number of streams being merged using 'mergeMapWith'.
365-- /Internal/
365-- /Internal/
366{-# INLINE mergeByM2 #-}
366{-# INLINE mergeByM2 #-}
@@ -400,7 +400,7 @@ mergeFstBy _f _m1 _m2 = undefined
400unfoldMany ::Monad m => Unfold m a b -> Stream m a -> Stream m b
400unfoldMany ::Monad m => Unfold m a b -> Stream m a -> Stream m b
401unfoldMany u m = fromStreamD $ D.unfoldMany u (toStreamD m)
401unfoldMany u m = fromStreamD $ D.unfoldMany u (toStreamD m)
403−-- | This does not pair streams like concatPairsWith, instead, it goes through
403+-- | This does not pair streams like mergeMapWith, instead, it goes through
404-- each stream one by one and yields one element from each stream. After it
404-- each stream one by one and yields one element from each stream. After it
405-- goes to the last stream it reverses the traversal to come back to the first
405-- goes to the last stream it reverses the traversal to come back to the first
406-- stream yielding elements from each stream on its way back to the first
406-- stream yielding elements from each stream on its way back to the first
@@ -411,7 +411,7 @@ unfoldMany u m = fromStreamD $ D.unfoldMany u (toStreamD m)
411-- >>> Stream.fold Fold.toList interleaved
411-- >>> Stream.fold Fold.toList interleaved
412-- [1,2,3,4,5,5,4,3,2,1]
412-- [1,2,3,4,5,5,4,3,2,1]
414−-- Note that this is order of magnitude more efficient than "concatPairsWith
414+-- Note that this is order of magnitude more efficient than "mergeMapWith
415-- wSerial" because of fusion.
415-- wSerial" because of fusion.
417-- /Fused/
417-- /Fused/
@@ -581,24 +581,24 @@ concatSmapMWith combine f initial =
581-- >>> s = Stream.fromList [5,1,7,9,2]
581-- >>> s = Stream.fromList [5,1,7,9,2]
582-- >>> generate = Stream.fromPure
582-- >>> generate = Stream.fromPure
583-- >>> combine = Stream.mergeBy compare
583-- >>> combine = Stream.mergeBy compare
584−-- >>> Stream.fold Fold.toList $ Stream.concatPairsWith combine generate s
584+-- >>> Stream.fold Fold.toList $ Stream.mergeMapWith combine generate s
585-- [1,2,5,7,9]
585-- [1,2,5,7,9]
587-- Note that if the stream length is not a power of 2, the binary tree composed
587-- Note that if the stream length is not a power of 2, the binary tree composed
588−-- by concatPairsWith would not be balanced, which may or may not be important
588+-- by mergeMapWith would not be balanced, which may or may not be important
589-- depending on what you are trying to achieve.
589-- depending on what you are trying to achieve.
591-- /Caution: the stream of streams must be finite/
591-- /Caution: the stream of streams must be finite/
593-- /Pre-release/
593-- /Pre-release/
595−{-# INLINE concatPairsWith #-}
595+{-# INLINE mergeMapWith #-}
596−concatPairsWith ::
596+mergeMapWith ::
597 (Stream m b -> Stream m b -> Stream m b)
597 (Stream m b -> Stream m b -> Stream m b)
598 -> (a -> Stream m b)
598 -> (a -> Stream m b)
599 -> Stream m a
599 -> Stream m a
600 -> Stream m b
600 -> Stream m b
601−concatPairsWith par f m =
601+mergeMapWith par f m =
602 fromStreamK
602 fromStreamK
603 $ K.concatPairsWith
603 $ K.concatPairsWith
604 (\s1 s2 -> toStreamK $ fromStreamK s1 `par` fromStreamK s2)
604 (\s1 s2 -> toStreamK $ fromStreamK s1 `par` fromStreamK s2)