@@ -85,8 +85,8 @@ module Streamly.Internal.Data.Stream.Nesting
85
85
-- intercalate.
86
86
, unfoldEachFoldBy
87
87
, ConcatUnfoldInterleaveState (.. )
88
- , unfoldEachInterleave -- bfsUnfoldEach
89
- , unfoldEachInterleaveRev -- altBfsUnfoldEach -- alternating directions
88
+ , bfsUnfoldEach
89
+ , altBfsUnfoldEach
90
90
91
91
-- *** unfoldEach joined by elements
92
92
-- | Like unfoldEach but intersperses an element between the streams after
@@ -112,7 +112,7 @@ module Streamly.Internal.Data.Stream.Nesting
112
112
113
113
-- | Like unfoldEach but schedules the generated streams based on time
114
114
-- slice instead of based on the outputs.
115
- , unfoldEachRoundRobin -- unfoldSched
115
+ , unfoldSched
116
116
-- , altUnfoldSched -- alternating directions
117
117
-- , fairUnfoldSched
118
118
@@ -198,6 +198,9 @@ module Streamly.Internal.Data.Stream.Nesting
198
198
, parseIterateD
199
199
, groupsBy
200
200
, splitOnSeq
201
+ , unfoldEachInterleave
202
+ , unfoldEachInterleaveRev
203
+ , unfoldEachRoundRobin
201
204
)
202
205
where
203
206
@@ -764,23 +767,18 @@ data ConcatUnfoldInterleaveState o i =
764
767
-- XXX Instead of using "reverse" build the list in the correct order to begin
765
768
-- with.
766
769
767
- -- | Like 'unfoldEach' but interleaves the resulting streams instead of
768
- -- appending them. Unfolds each element in the input stream to a stream and
769
- -- then interleave the resulting streams.
770
+ -- | Like 'unfoldEach' but interleaves the resulting streams in a breadth first
771
+ -- manner instead of appending them. Unfolds each element in the input stream
772
+ -- to a stream and then interleave the resulting streams.
770
773
--
771
774
-- >>> lists = Stream.fromList [[1,4,7],[2,5,8],[3,6,9]]
772
- -- >>> Stream.toList $ Stream.unfoldEachInterleave Unfold.fromList lists
775
+ -- >>> Stream.toList $ Stream.bfsUnfoldEach Unfold.fromList lists
773
776
-- [1,2,3,4,5,6,7,8,9]
774
777
--
775
- -- This is similar to 'mergeMapWith' using 'Streamly.Data.StreamK.interleave'
776
- -- but an order of magnitude more efficient due to fusion.
777
- --
778
- -- See also 'mergeMapWith'.
779
- --
780
- {-# INLINE_NORMAL unfoldEachInterleave #-}
781
- unfoldEachInterleave :: Monad m =>
778
+ {-# INLINE_NORMAL bfsUnfoldEach #-}
779
+ bfsUnfoldEach , unfoldEachInterleave :: Monad m =>
782
780
Unfold m a b -> Stream m a -> Stream m b
783
- unfoldEachInterleave (Unfold istep inject) (Stream ostep ost) =
781
+ bfsUnfoldEach (Unfold istep inject) (Stream ostep ost) =
784
782
Stream step (ConcatUnfoldInterleaveOuter ost [] )
785
783
786
784
where
@@ -825,18 +823,21 @@ unfoldEachInterleave (Unfold istep inject) (Stream ostep ost) =
825
823
Skip s -> Skip (ConcatUnfoldInterleaveInnerR ls (s: rs))
826
824
Stop -> Skip (ConcatUnfoldInterleaveInnerR ls rs)
827
825
828
- -- | Like 'unfoldEachInterleave' but reverses the traversal direction after
829
- -- reaching the last stream. This could be little bit more efficient if the
830
- -- order of traversal is not important.
826
+ RENAME (unfoldEachInterleave, bfsUnfoldEach)
827
+
828
+ -- | Like 'bfsUnfoldEach' but reverses the traversal direction after reaching
829
+ -- the last stream and then after reaching the first stream, thus alternating
830
+ -- the directions. This could be a little bit more efficient if the order of
831
+ -- traversal is not important.
831
832
--
832
833
-- >>> lists = Stream.fromList [[1,4,7],[2,5,8],[3,6,9]]
833
- -- >>> Stream.toList $ Stream.unfoldEachInterleaveRev Unfold.fromList lists
834
+ -- >>> Stream.toList $ Stream.altBfsUnfoldEach Unfold.fromList lists
834
835
-- [1,2,3,6,5,4,7,8,9]
835
836
--
836
- {-# INLINE_NORMAL unfoldEachInterleaveRev #-}
837
- unfoldEachInterleaveRev , unfoldInterleave :: Monad m =>
837
+ {-# INLINE_NORMAL altBfsUnfoldEach #-}
838
+ altBfsUnfoldEach , unfoldEachInterleaveRev , unfoldInterleave :: Monad m =>
838
839
Unfold m a b -> Stream m a -> Stream m b
839
- unfoldEachInterleaveRev (Unfold istep inject) (Stream ostep ost) =
840
+ altBfsUnfoldEach (Unfold istep inject) (Stream ostep ost) =
840
841
Stream step (ConcatUnfoldInterleaveOuter ost [] )
841
842
842
843
where
@@ -881,7 +882,8 @@ unfoldEachInterleaveRev (Unfold istep inject) (Stream ostep ost) =
881
882
Skip s -> Skip (ConcatUnfoldInterleaveInnerR ls (s: rs))
882
883
Stop -> Skip (ConcatUnfoldInterleaveInnerR ls rs)
883
884
884
- RENAME (unfoldInterleave,unfoldEachInterleaveRev)
885
+ RENAME (unfoldInterleave,altBfsUnfoldEach)
886
+ RENAME (unfoldEachInterleaveRev,altBfsUnfoldEach)
885
887
886
888
-- XXX In general we can use different scheduling strategies e.g. how to
887
889
-- schedule the outer vs inner loop or assigning weights to different streams
@@ -891,16 +893,18 @@ RENAME(unfoldInterleave,unfoldEachInterleaveRev)
891
893
--
892
894
-- Compared to unfoldEachInterleave this one switches streams on Skips.
893
895
894
- -- | 'unfoldEachInterleave ' switches to the next stream whenever a value from a
896
+ -- | 'bfdUnfoldEach ' switches to the next stream whenever a value from a
895
897
-- stream is yielded, it does not switch on a 'Skip'. So if a stream keeps
896
898
-- skipping for long time other streams won't get a chance to run.
897
- -- 'unfoldEachRoundRobin ' switches on Skip as well. So it basically schedules each
899
+ -- 'unfoldSched ' switches on Skip as well. So it basically schedules each
898
900
-- stream fairly irrespective of whether it produces a value or not.
899
901
--
900
- {-# INLINE_NORMAL unfoldEachRoundRobin #-}
901
- unfoldEachRoundRobin , unfoldRoundRobin :: Monad m =>
902
+ -- An N-ary version of 'roundRobin'.
903
+ --
904
+ {-# INLINE_NORMAL unfoldSched #-}
905
+ unfoldSched , unfoldEachRoundRobin , unfoldRoundRobin :: Monad m =>
902
906
Unfold m a b -> Stream m a -> Stream m b
903
- unfoldEachRoundRobin (Unfold istep inject) (Stream ostep ost) =
907
+ unfoldSched (Unfold istep inject) (Stream ostep ost) =
904
908
Stream step (ConcatUnfoldInterleaveOuter ost [] )
905
909
where
906
910
{-# INLINE_LATE step #-}
@@ -945,7 +949,8 @@ unfoldEachRoundRobin (Unfold istep inject) (Stream ostep ost) =
945
949
Skip s -> Skip (ConcatUnfoldInterleaveInnerR (s: ls) rs)
946
950
Stop -> Skip (ConcatUnfoldInterleaveInnerR ls rs)
947
951
948
- RENAME (unfoldRoundRobin,unfoldEachRoundRobin)
952
+ RENAME (unfoldRoundRobin,unfoldSched)
953
+ RENAME (unfoldEachRoundRobin,unfoldSched)
949
954
950
955
-- | Round robin co-operative scheduling of multiple streams.
951
956
--
0 commit comments