on master help sign in
Use "cons" instead of "combine" in iteration

There is no advantage of combine as we prepending a single pure element.

commit9653495755782dc5285346e4751cc3b4adf549ce authorHarendra Kumar <harendra@composewell.com> dateSun 1 Jan 2023, 08:42 (4 years ago) parent83bca76
1 file changed+5−6
core/src/Streamly/Internal/Data/Stream/Expand.hs+5−6
core/src/Streamly/Internal/Data/Stream/Expand.hs+5−6
@@ -141,11 +141,10 @@ where
141141#include "inline.hs"
142142
143143import Streamly.Internal.Data.Stream.Bottom
144− ( concatEffect, concatMapM, concatMap, smapM, fromPure
145− , zipWith, zipWithM)
144+ ( concatEffect, concatMapM, concatMap, smapM, zipWith, zipWithM)
146145import Streamly.Internal.Data.Stream.Type
147146 ( Stream, fromStreamD, fromStreamK, toStreamD, toStreamK
148− , bindWith, concatMapWith, nil)
147+ , bindWith, concatMapWith, cons, nil)
149148import Streamly.Internal.Data.Unfold.Type (Unfold)
150149
151150import qualified Streamly.Internal.Data.Stream.StreamD as D
@@ -674,7 +673,7 @@ iterateConcatMapWith combine f = iterateStream
674673
675674 iterateStream = concatMapWith combine generate
676675
677− generate x = fromPure x `combine` iterateStream (f x)
676+ generate x = x `cons` iterateStream (f x)
678677
679678-- | Traverse the stream in depth first style (DFS). Map each element in the
680679-- input stream to a stream and flatten, recursively map the resulting elements
@@ -758,7 +757,7 @@ iterateMergeMapWith combine f = iterateStream
758757
759758 iterateStream = mergeMapWith combine generate
760759
761− generate x = fromPure x `combine` iterateStream (f x)
760+ generate x = x `cons` iterateStream (f x)
762761
763762-- | Same as @iterateConcatMapDFS@ but more efficient due to stream fusion.
764763--
@@ -825,7 +824,7 @@ iterateConcatScanWith combine f initial stream =
825824
826825 iterateStream (b, s) = pure $ concatMapWith combine (generate b) s
827826
828− generate b a = fromPure a `combine` feedback b a
827+ generate b a = a `cons` feedback b a
829828
830829 feedback b a = concatEffect $ f b a >>= iterateStream
831830