on master help sign in
Rename iterateConcatMap to concatIterate etc.
commita89a791dc3238103d43d62305c9f6059360eda29 authorHarendra Kumar <harendra@composewell.com> dateSun 1 Jan 2023, 12:09 (4 years ago) parentf65264e
3 files changed+106−105
core/src/Streamly/Internal/Data/Stream/Expand.hs+69−69 core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+29−29 src/Streamly/Internal/Data/Stream/Concurrent.hs+8−7
core/src/Streamly/Internal/Data/Stream/Expand.hs+69−69
@@ -120,21 +120,21 @@ module Streamly.Internal.Data.Stream.Expand
120120
121121 -- * Iterate
122122 -- | Map and flatten Trees of Streams
123− , iterateUnfoldManyDFS
124− , iterateUnfoldManyBFS
125− , iterateUnfoldManyBFSRev
123+ , unfoldIterateDfs
124+ , unfoldIterateBfs
125+ , unfoldIterateBfsRev
126126
127− , iterateConcatMapWith
128− , iterateMergeMapWith
127+ , concatIterateWith
128+ , mergeIterateWith
129129
130− , iterateConcatMapDFS
131− , iterateConcatMapBFS
130+ , concatIterateDfs
131+ , concatIterateBfs
132132
133133 -- More experimental ops
134− , iterateConcatMapBFSRev
135− , iterateLeftsConcatMapWith
136− , iterateConcatScanWith
137− , iterateConcatScan
134+ , concatIterateBfsRev
135+ , concatIterateLeftsWith
136+ , concatIterateScanWith
137+ , concatIterateScan
138138 )
139139where
140140
@@ -639,7 +639,7 @@ mergeMapWith par f m =
639639 (toStreamK m)
640640
641641------------------------------------------------------------------------------
642−-- iterateConcatMap - Map and flatten Trees of Streams
642+-- concatIterate - Map and flatten Trees of Streams
643643------------------------------------------------------------------------------
644644
645645-- | Yield an input element in the output stream, map a stream generator on it
@@ -651,23 +651,23 @@ mergeMapWith par f m =
651651--
652652-- >>> f = either Dir.readEitherPaths (const Stream.nil)
653653-- >>> input = Stream.fromPure (Left ".")
654−-- >>> ls = Stream.iterateConcatMapWith Stream.append f input
654+-- >>> ls = Stream.concatIterateWith Stream.append f input
655655--
656−-- Note that 'iterateM' is a special case of 'iterateConcatMapWith':
656+-- Note that 'iterateM' is a special case of 'concatIterateWith':
657657--
658−-- >>> iterateM f = Stream.iterateConcatMapWith Stream.append (Stream.fromEffect . f) . Stream.fromEffect
658+-- >>> iterateM f = Stream.concatIterateWith Stream.append (Stream.fromEffect . f) . Stream.fromEffect
659659--
660660-- /CPS/
661661--
662662-- /Pre-release/
663663--
664−{-# INLINE iterateConcatMapWith #-}
665−iterateConcatMapWith ::
664+{-# INLINE concatIterateWith #-}
665+concatIterateWith ::
666666 (Stream m a -> Stream m a -> Stream m a)
667667 -> (a -> Stream m a)
668668 -> Stream m a
669669 -> Stream m a
670−iterateConcatMapWith combine f = iterateStream
670+concatIterateWith combine f = iterateStream
671671
672672 where
673673
@@ -683,21 +683,21 @@ iterateConcatMapWith combine f = iterateStream
683683--
684684-- >>> f = either (Just . Dir.readEitherPaths) (const Nothing)
685685-- >>> input = Stream.fromPure (Left ".")
686−-- >>> ls = Stream.iterateConcatMapDFS f input
686+-- >>> ls = Stream.concatIterateDfs f input
687687--
688−-- This is equivalent to using @iterateConcatMapWith Stream.append@.
688+-- This is equivalent to using @concatIterateWith Stream.append@.
689689--
690690-- /Pre-release/
691−{-# INLINE iterateConcatMapDFS #-}
692−iterateConcatMapDFS :: Monad m =>
691+{-# INLINE concatIterateDfs #-}
692+concatIterateDfs :: Monad m =>
693693 (a -> Maybe (Stream m a))
694694 -> Stream m a
695695 -> Stream m a
696−iterateConcatMapDFS f stream =
696+concatIterateDfs f stream =
697697 fromStreamD
698− $ D.iterateConcatMapDFS (fmap toStreamD . f ) (toStreamD stream)
698+ $ D.concatIterateDfs (fmap toStreamD . f ) (toStreamD stream)
699699
700−-- | Similar to 'iterateConcatMapDFS' except that it traverses the stream in
700+-- | Similar to 'concatIterateDfs' except that it traverses the stream in
701701-- breadth first style (BFS). First, all the elements in the input stream are
702702-- emitted, and then their traversals are emitted.
703703--
@@ -705,33 +705,33 @@ iterateConcatMapDFS f stream =
705705--
706706-- >>> f = either (Just . Dir.readEitherPaths) (const Nothing)
707707-- >>> input = Stream.fromPure (Left ".")
708−-- >>> ls = Stream.iterateConcatMapBFS f input
708+-- >>> ls = Stream.concatIterateBfs f input
709709--
710710-- /Pre-release/
711−{-# INLINE iterateConcatMapBFS #-}
712−iterateConcatMapBFS :: Monad m =>
711+{-# INLINE concatIterateBfs #-}
712+concatIterateBfs :: Monad m =>
713713 (a -> Maybe (Stream m a))
714714 -> Stream m a
715715 -> Stream m a
716−iterateConcatMapBFS f stream =
716+concatIterateBfs f stream =
717717 fromStreamD
718− $ D.iterateConcatMapBFS (fmap toStreamD . f ) (toStreamD stream)
718+ $ D.concatIterateBfs (fmap toStreamD . f ) (toStreamD stream)
719719
720−-- | Same as 'iterateConcatMapBFS' except that the traversal of the last
720+-- | Same as 'concatIterateBfs' except that the traversal of the last
721721-- element on a level is emitted first and then going backwards up to the first
722722-- element (reversed ordering). This may be slightly faster than
723−-- 'iterateConcatMapBFS'.
723+-- 'concatIterateBfs'.
724724--
725−{-# INLINE iterateConcatMapBFSRev #-}
726−iterateConcatMapBFSRev :: Monad m =>
725+{-# INLINE concatIterateBfsRev #-}
726+concatIterateBfsRev :: Monad m =>
727727 (a -> Maybe (Stream m a))
728728 -> Stream m a
729729 -> Stream m a
730−iterateConcatMapBFSRev f stream =
730+concatIterateBfsRev f stream =
731731 fromStreamD
732− $ D.iterateConcatMapBFSRev (fmap toStreamD . f ) (toStreamD stream)
732+ $ D.concatIterateBfsRev (fmap toStreamD . f ) (toStreamD stream)
733733
734−-- | Like 'iterateConcatMapWith' but uses the pairwise flattening combinator
734+-- | Like 'concatIterateWith' but uses the pairwise flattening combinator
735735-- 'mergeMapWith' for flattening the resulting streams. This can be used for a
736736-- balanced traversal of a tree like structure.
737737--
@@ -739,19 +739,19 @@ iterateConcatMapBFSRev f stream =
739739--
740740-- >>> f = either Dir.readEitherPaths (const Stream.nil)
741741-- >>> input = Stream.fromPure (Left ".")
742−-- >>> ls = Stream.iterateMergeMapWith Stream.interleave f input
742+-- >>> ls = Stream.mergeIterateWith Stream.interleave f input
743743--
744744-- /CPS/
745745--
746746-- /Pre-release/
747747--
748−{-# INLINE iterateMergeMapWith #-}
749−iterateMergeMapWith ::
748+{-# INLINE mergeIterateWith #-}
749+mergeIterateWith ::
750750 (Stream m a -> Stream m a -> Stream m a)
751751 -> (a -> Stream m a)
752752 -> Stream m a
753753 -> Stream m a
754−iterateMergeMapWith combine f = iterateStream
754+mergeIterateWith combine f = iterateStream
755755
756756 where
757757
@@ -759,34 +759,34 @@ iterateMergeMapWith combine f = iterateStream
759759
760760 generate x = x `cons` iterateStream (f x)
761761
762−-- | Same as @iterateConcatMapDFS@ but more efficient due to stream fusion.
762+-- | Same as @concatIterateDfs@ but more efficient due to stream fusion.
763763--
764764-- Example, list a directory tree using DFS:
765765--
766766-- >>> f = Unfold.either Dir.eitherReaderPaths Unfold.nil
767767-- >>> input = Stream.fromPure (Left ".")
768−-- >>> ls = Stream.iterateUnfoldManyDFS f input
768+-- >>> ls = Stream.unfoldIterateDfs f input
769769--
770770-- /Pre-release/
771−{-# INLINE iterateUnfoldManyDFS #-}
772−iterateUnfoldManyDFS :: Monad m => Unfold m a a -> Stream m a -> Stream m a
773−iterateUnfoldManyDFS u = fromStreamD . D.iterateUnfoldManyDFS u . toStreamD
771+{-# INLINE unfoldIterateDfs #-}
772+unfoldIterateDfs :: Monad m => Unfold m a a -> Stream m a -> Stream m a
773+unfoldIterateDfs u = fromStreamD . D.unfoldIterateDfs u . toStreamD
774774
775−-- | Like 'iterateUnfoldManyDFS' but uses breadth first style traversal.
775+-- | Like 'unfoldIterateDfs' but uses breadth first style traversal.
776776--
777777-- /Pre-release/
778−{-# INLINE iterateUnfoldManyBFS #-}
779−iterateUnfoldManyBFS :: Monad m => Unfold m a a -> Stream m a -> Stream m a
780−iterateUnfoldManyBFS u = fromStreamD . D.iterateUnfoldManyBFS u . toStreamD
778+{-# INLINE unfoldIterateBfs #-}
779+unfoldIterateBfs :: Monad m => Unfold m a a -> Stream m a -> Stream m a
780+unfoldIterateBfs u = fromStreamD . D.unfoldIterateBfs u . toStreamD
781781
782−-- | Like 'iterateUnfoldManyBFS' but processes the children in reverse order,
782+-- | Like 'unfoldIterateBfs' but processes the children in reverse order,
783783-- therefore, may be slightly faster.
784784--
785785-- /Pre-release/
786−{-# INLINE iterateUnfoldManyBFSRev #-}
787−iterateUnfoldManyBFSRev :: Monad m => Unfold m a a -> Stream m a -> Stream m a
788−iterateUnfoldManyBFSRev u =
789− fromStreamD . D.iterateUnfoldManyBFSRev u . toStreamD
786+{-# INLINE unfoldIterateBfsRev #-}
787+unfoldIterateBfsRev :: Monad m => Unfold m a a -> Stream m a -> Stream m a
788+unfoldIterateBfsRev u =
789+ fromStreamD . D.unfoldIterateBfsRev u . toStreamD
790790
791791------------------------------------------------------------------------------
792792-- Flattening Graphs
@@ -807,15 +807,15 @@ iterateUnfoldManyBFSRev u =
807807--
808808-- /Pre-release/
809809--
810−{-# INLINE iterateConcatScanWith #-}
811−iterateConcatScanWith
810+{-# INLINE concatIterateScanWith #-}
811+concatIterateScanWith
812812 :: Monad m
813813 => (Stream m a -> Stream m a -> Stream m a)
814814 -> (b -> a -> m (b, Stream m a))
815815 -> m b
816816 -> Stream m a
817817 -> Stream m a
818−iterateConcatScanWith combine f initial stream =
818+concatIterateScanWith combine f initial stream =
819819 concatEffect $ do
820820 b <- initial
821821 iterateStream (b, stream)
@@ -835,16 +835,16 @@ iterateConcatScanWith combine f initial stream =
835835-- stream and keep building a buffered list/stream, once done we can then
836836-- process the buffered stream.
837837
838−{-# INLINE iterateConcatScan #-}
839−iterateConcatScan
838+{-# INLINE concatIterateScan #-}
839+concatIterateScan
840840 :: Monad m
841841 => (b -> a -> m b)
842842 -> (b -> m (Maybe (b, Stream m a)))
843843 -> b
844844 -> Stream m a
845−iterateConcatScan scanner generate initial =
845+concatIterateScan scanner generate initial =
846846 fromStreamD
847− $ D.iterateConcatScan
847+ $ D.concatIterateScan
848848 scanner (fmap (fmap (fmap toStreamD)) . generate) initial
849849
850850------------------------------------------------------------------------------
@@ -871,23 +871,23 @@ concatMapEitherWith = undefined
871871-- This API should perhaps be removed in favor of those.
872872
873873-- | In an 'Either' stream iterate on 'Left's. This is a special case of
874−-- 'iterateConcatMapWith':
874+-- 'concatIterateWith':
875875--
876−-- >>> iterateLeftsConcatMapWith combine f = Stream.iterateConcatMapWith combine (either f (const Stream.nil))
876+-- >>> concatIterateLeftsWith combine f = Stream.concatIterateWith combine (either f (const Stream.nil))
877877--
878878-- To traverse a directory tree:
879879--
880880-- >>> input = Stream.fromPure (Left ".")
881−-- >>> ls = Stream.iterateLeftsConcatMapWith Stream.append Dir.readEither input
881+-- >>> ls = Stream.concatIterateLeftsWith Stream.append Dir.readEither input
882882--
883883-- /Pre-release/
884884--
885−{-# INLINE iterateLeftsConcatMapWith #-}
886−iterateLeftsConcatMapWith
885+{-# INLINE concatIterateLeftsWith #-}
886+concatIterateLeftsWith
887887 :: (b ~ Either a c)
888888 => (Stream m b -> Stream m b -> Stream m b)
889889 -> (a -> Stream m b)
890890 -> Stream m b
891891 -> Stream m b
892−iterateLeftsConcatMapWith combine f =
893− iterateConcatMapWith combine (either f (const nil))
892+concatIterateLeftsWith combine f =
893+ concatIterateWith combine (either f (const nil))
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+29−29
@@ -89,14 +89,14 @@ module Streamly.Internal.Data.Stream.StreamD.Type
8989 , concatMapM
9090 , concatEffect
9191
92− , iterateUnfoldManyDFS
93− , iterateUnfoldManyBFS
94− , iterateUnfoldManyBFSRev
92+ , unfoldIterateDfs
93+ , unfoldIterateBfs
94+ , unfoldIterateBfsRev
9595
96− , iterateConcatScan
97− , iterateConcatMapDFS
98− , iterateConcatMapBFS
99− , iterateConcatMapBFSRev
96+ , concatIterateScan
97+ , concatIterateDfs
98+ , concatIterateBfs
99+ , concatIterateBfsRev
100100
101101 , FoldMany (..) -- for inspection testing
102102 , FoldManyPost (..)
@@ -897,13 +897,13 @@ instance Monad m => Monad (Stream m) where
897897-- | Generate a stream from an initial state, scan and concat the stream,
898898-- generate a stream again from the final state of the previous scan and repeat
899899-- the process.
900−{-# INLINE_NORMAL iterateConcatScan #-}
901−iterateConcatScan :: Monad m =>
900+{-# INLINE_NORMAL concatIterateScan #-}
901+concatIterateScan :: Monad m =>
902902 (b -> a -> m b)
903903 -> (b -> m (Maybe (b, Stream m a)))
904904 -> b
905905 -> Stream m a
906−iterateConcatScan scanner generate initial = Stream step (Left initial)
906+concatIterateScan scanner generate initial = Stream step (Left initial)
907907
908908 where
909909
@@ -929,15 +929,15 @@ iterateConcatScan scanner generate initial = Stream step (Left initial)
929929-- have to store any state. This makes the stored state proportional to the
930930-- number of non-leaf nodes rather than total number of nodes.
931931
932−-- | This function may be slightly faster than iterateConcatMapBFS because it
932+-- | This function may be slightly faster than concatIterateBfs because it
933933-- traverses the elements on a level in reverse order, therefore, does not have
934934-- to reverse the list stroing those.
935−{-# INLINE_NORMAL iterateConcatMapBFSRev #-}
936−iterateConcatMapBFSRev :: Monad m =>
935+{-# INLINE_NORMAL concatIterateBfsRev #-}
936+concatIterateBfsRev :: Monad m =>
937937 (a -> Maybe (Stream m a))
938938 -> Stream m a
939939 -> Stream m a
940−iterateConcatMapBFSRev f stream = Stream step (stream, [])
940+concatIterateBfsRev f stream = Stream step (stream, [])
941941
942942 where
943943
@@ -957,12 +957,12 @@ iterateConcatMapBFSRev f stream = Stream step (stream, [])
957957 (y:ys) -> return $ Skip (y, ys)
958958 [] -> return Stop
959959
960−{-# INLINE_NORMAL iterateConcatMapBFS #-}
961−iterateConcatMapBFS :: Monad m =>
960+{-# INLINE_NORMAL concatIterateBfs #-}
961+concatIterateBfs :: Monad m =>
962962 (a -> Maybe (Stream m a))
963963 -> Stream m a
964964 -> Stream m a
965−iterateConcatMapBFS f stream = Stream step (stream, [], [])
965+concatIterateBfs f stream = Stream step (stream, [], [])
966966
967967 where
968968
@@ -985,12 +985,12 @@ iterateConcatMapBFS f stream = Stream step (stream, [], [])
985985 (x:xs1) -> return $ Skip (x, xs1, [])
986986 [] -> return Stop
987987
988−{-# INLINE_NORMAL iterateConcatMapDFS #-}
989−iterateConcatMapDFS :: Monad m =>
988+{-# INLINE_NORMAL concatIterateDfs #-}
989+concatIterateDfs :: Monad m =>
990990 (a -> Maybe (Stream m a))
991991 -> Stream m a
992992 -> Stream m a
993−iterateConcatMapDFS f stream = Stream step (stream, [])
993+concatIterateDfs f stream = Stream step (stream, [])
994994
995995 where
996996
@@ -1015,12 +1015,12 @@ data IterateUnfoldState o i =
10151015 IterateUnfoldOuter o
10161016 | IterateUnfoldInner o i [i]
10171017
1018−{-# INLINE_NORMAL iterateUnfoldManyDFS #-}
1019−iterateUnfoldManyDFS :: Monad m =>
1018+{-# INLINE_NORMAL unfoldIterateDfs #-}
1019+unfoldIterateDfs :: Monad m =>
10201020 Unfold m a a
10211021 -> Stream m a
10221022 -> Stream m a
1023−iterateUnfoldManyDFS (Unfold istep inject) (Stream ostep ost) =
1023+unfoldIterateDfs (Unfold istep inject) (Stream ostep ost) =
10241024 Stream step (IterateUnfoldOuter ost)
10251025
10261026 where
@@ -1052,12 +1052,12 @@ data IterateUnfoldBFSRevState o i =
10521052 IterateUnfoldBFSRevOuter o [i]
10531053 | IterateUnfoldBFSRevInner i [i]
10541054
1055−{-# INLINE_NORMAL iterateUnfoldManyBFSRev #-}
1056−iterateUnfoldManyBFSRev :: Monad m =>
1055+{-# INLINE_NORMAL unfoldIterateBfsRev #-}
1056+unfoldIterateBfsRev :: Monad m =>
10571057 Unfold m a a
10581058 -> Stream m a
10591059 -> Stream m a
1060−iterateUnfoldManyBFSRev (Unfold istep inject) (Stream ostep ost) =
1060+unfoldIterateBfsRev (Unfold istep inject) (Stream ostep ost) =
10611061 Stream step (IterateUnfoldBFSRevOuter ost [])
10621062
10631063 where
@@ -1092,12 +1092,12 @@ data IterateUnfoldBFSState o i =
10921092 IterateUnfoldBFSOuter o [i]
10931093 | IterateUnfoldBFSInner i [i] [i]
10941094
1095−{-# INLINE_NORMAL iterateUnfoldManyBFS #-}
1096−iterateUnfoldManyBFS :: Monad m =>
1095+{-# INLINE_NORMAL unfoldIterateBfs #-}
1096+unfoldIterateBfs :: Monad m =>
10971097 Unfold m a a
10981098 -> Stream m a
10991099 -> Stream m a
1100−iterateUnfoldManyBFS (Unfold istep inject) (Stream ostep ost) =
1100+unfoldIterateBfs (Unfold istep inject) (Stream ostep ost) =
11011101 Stream step (IterateUnfoldBFSOuter ost [])
11021102
11031103 where
src/Streamly/Internal/Data/Stream/Concurrent.hs+8−7
@@ -102,8 +102,8 @@ module Streamly.Internal.Data.Stream.Concurrent
102102 , concatMapInterleave
103103 , parConcatMap
104104
105− -- *** Iterate
106− , parIterateConcatMap
105+ -- *** ConcatIterate
106+ , parConcatIterate
107107
108108 -- ** Reactive
109109 , fromCallback
@@ -705,18 +705,19 @@ parZipWith :: MonadAsync m
705705parZipWith cfg f = parZipWithM cfg (\a b -> return $ f a b)
706706
707707-------------------------------------------------------------------------------
708−-- iterateConcatMap
708+-- concatIterate
709709-------------------------------------------------------------------------------
710710
711−-- | Same as 'iterateConcatMap' but concurrent.
711+-- | Same as 'concatIterate' but concurrent.
712712--
713−{-# INLINE parIterateConcatMap #-}
714−parIterateConcatMap :: MonadAsync m =>
713+-- /Pre-release/
714+{-# INLINE parConcatIterate #-}
715+parConcatIterate :: MonadAsync m =>
715716 (Config -> Config)
716717 -> (a -> Stream m a)
717718 -> Stream m a
718719 -> Stream m a
719−parIterateConcatMap modifier f input =
720+parConcatIterate modifier f input =
720721 Stream.fromStreamK
721722 $ withChannelK modifier (Stream.toStreamK input) iterateStream
722723