on master help sign in
Rename concatM to concatEffect and expose it
commitac2ee38449364b44a869f2058b5e4e5be8f85f7a authorHarendra Kumar <harendra@composewell.com> dateThu 17 Nov 2022, 09:36 (4 years ago) parent2e4b883
8 files changed+25−24
benchmark/Streamly/Benchmark/Data/Stream/Expand.hs+1−1 benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+2−2 core/src/Streamly/Data/Stream.hs+1 core/src/Streamly/Internal/Data/Stream/Bottom.hs+8−7 core/src/Streamly/Internal/Data/Stream/Expand.hs+2−2 core/src/Streamly/Internal/Data/Stream/Top.hs+7−7 src/Streamly/Internal/Data/Stream/Concurrent.hs+1−1 src/Streamly/Internal/Data/Stream/Extra.hs+3−4
benchmark/Streamly/Benchmark/Data/Stream/Expand.hs+1−1
@@ -410,7 +410,7 @@ o_1_space_monad value =
410410-- new prime we keep appending a division filter for all the future numbers.
411411{-# INLINE sieve #-}
412412sieve :: Monad m => Stream m Int -> Stream m Int
413−sieve s = S.concatM $ do
413+sieve s = S.concatEffect $ do
414414 r <- S.uncons s
415415 case r of
416416 Just (prime, rest) ->
benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+2−2
@@ -96,7 +96,7 @@ iterateStateIO n = do
9696
9797{-# INLINE iterateStateT #-}
9898iterateStateT :: Int -> Stream (StateT Int IO) Int
99−iterateStateT n = Stream.concatM $ do
99+iterateStateT n = Stream.concatEffect $ do
100100 x <- get
101101 if x > n
102102 then do
@@ -109,7 +109,7 @@ iterateStateT n = Stream.concatM $ do
109109iterateState :: Monad m =>
110110 Int
111111 -> Stream (StateT Int m) Int
112−iterateState n = Stream.concatM $ do
112+iterateState n = Stream.concatEffect $ do
113113 x <- get
114114 if x > n
115115 then do
core/src/Streamly/Data/Stream.hs+1
@@ -401,6 +401,7 @@ module Streamly.Data.Stream
401401 -- > filter p m = S.concatMap (\x -> if p x then S.fromPure x else S.nil) m
402402 --
403403
404+ , concatEffect
404405 , concatMapWith
405406 , concatMap
406407 , concatMapM
core/src/Streamly/Internal/Data/Stream/Bottom.hs+8−7
@@ -52,7 +52,7 @@ module Streamly.Internal.Data.Stream.Bottom
5252 , reverse'
5353
5454 -- * Expand
55− , concatM
55+ , concatEffect
5656 , concatMapM
5757 , concatMap
5858
@@ -580,20 +580,21 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
580580concatMap ::Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
581581concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
582582
583+-- >>> concatEffect = Stream.concat . lift -- requires (MonadTrans t)
584+-- >>> concatEffect = join . lift -- requires (MonadTrans t, Monad (Stream m))
585+
583586-- | Given a stream value in the underlying monad, lift and join the underlying
584587-- monad with the stream monad.
585588--
586−-- >>> concatM = Stream.concat . Stream.fromEffect
587−-- >>> concatM = Stream.concat . lift -- requires (MonadTrans t)
588−-- >>> concatM = join . lift -- requires (MonadTrans t, Monad (Stream m))
589+-- >>> concatEffect = Stream.concat . Stream.fromEffect
589590--
590591-- See also: 'concat', 'sequence'
591592--
592593-- /Internal/
593594--
594−{-# INLINE concatM #-}
595−concatM :: Monad m => m (Stream m a) -> Stream m a
596−concatM generator = concatMapM (\() -> generator) (fromPure ())
595+{-# INLINE concatEffect #-}
596+concatEffect :: Monad m => m (Stream m a) -> Stream m a
597+concatEffect generator = concatMapM (\() -> generator) (fromPure ())
597598
598599-- XXX Need a more intuitive name, and need to reconcile the names
599600-- foldMany/fold/parse/parseMany/parseManyPost etc.
core/src/Streamly/Internal/Data/Stream/Expand.hs+2−2
@@ -92,7 +92,7 @@ module Streamly.Internal.Data.Stream.Expand
9292 -- the binary append operation to append many streams.
9393 , concatMapM
9494 , concatMap
95− , concatM
95+ , concatEffect
9696 , concat
9797
9898 -- * ConcatMapWith
@@ -128,7 +128,7 @@ where
128128#include "inline.hs"
129129
130130import Streamly.Internal.Data.Stream.Bottom
131− ( concatM, concatMapM, concatMap, smapM, fromPure, fromEffect
131+ ( concatEffect, concatMapM, concatMap, smapM, fromPure, fromEffect
132132 , zipWith, zipWithM)
133133import Streamly.Internal.Data.Stream.Type
134134 ( Stream, fromStreamD, fromStreamK, toStreamD, toStreamK
core/src/Streamly/Internal/Data/Stream/Top.hs+7−7
@@ -252,7 +252,7 @@ joinLeft eq s1 s2 = Stream.evalStateT (return False) $ getCrossStream $ do
252252 -- XXX Is there a better way to perform some action at the end of a loop
253253 -- iteration?
254254 CrossStream (Stream.fromEffect $ put False)
255− let final = Stream.concatM $ do
255+ let final = Stream.concatEffect $ do
256256 r <- get
257257 if r
258258 then pure Stream.nil
@@ -300,7 +300,7 @@ joinOuter :: MonadIO m =>
300300 -> Stream m b
301301 -> Stream m (Maybe a, Maybe b)
302302joinOuter eq s1 s =
303− Stream.concatM $ do
303+ Stream.concatEffect $ do
304304 inputArr <- Array.fromStream s
305305 let len = Array.length inputArr
306306 foundArr <-
@@ -331,7 +331,7 @@ joinOuter eq s1 s =
331331 -- XXX Is there a better way to perform some action at the end of a loop
332332 -- iteration?
333333 CrossStream (Stream.fromEffect $ put False)
334− let final = Stream.concatM $ do
334+ let final = Stream.concatEffect $ do
335335 r <- get
336336 if r
337337 then pure Stream.nil
@@ -398,7 +398,7 @@ mergeOuterJoin _eq _s1 _s2 = undefined
398398intersectBy :: Monad m =>
399399 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
400400intersectBy eq s1 s2 =
401− Stream.concatM
401+ Stream.concatEffect
402402 $ do
403403 -- This may work well when s2 is small
404404 xs <- Stream.fold Fold.toListRev $ Stream.uniqBy eq s2
@@ -447,7 +447,7 @@ intersectBySorted eq s1 =
447447differenceBy :: (Monad m) =>
448448 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
449449differenceBy eq s1 s2 =
450− Stream.concatM
450+ Stream.concatEffect
451451 $ do
452452 -- This may work well if s1 is small
453453 -- If s1 is big we can go through s1, deleting elements from s2 and
@@ -492,7 +492,7 @@ mergeDifferenceBy _eq _s1 _s2 = undefined
492492unionBy :: MonadIO m =>
493493 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
494494unionBy eq s1 s2 =
495− Stream.concatM
495+ Stream.concatEffect
496496 $ do
497497 xs <- Stream.fold Fold.toList s2
498498 -- XXX we can use postscanlMAfter' instead of IORef
@@ -500,7 +500,7 @@ unionBy eq s1 s2 =
500500 let f x = do
501501 liftIO $ modifyIORef' ref (List.deleteBy eq x)
502502 return x
503− s3 = Stream.concatM
503+ s3 = Stream.concatEffect
504504 $ do
505505 xs1 <- liftIO $ readIORef ref
506506 return $ Stream.fromList xs1
src/Streamly/Internal/Data/Stream/Concurrent.hs+1−1
@@ -789,7 +789,7 @@ newCallbackStream = do
789789--
790790{-# INLINE fromCallback #-}
791791fromCallback :: MonadAsync m => ((a -> m ()) -> m ()) -> Stream m a
792−fromCallback setCallback = Stream.concatM $ do
792+fromCallback setCallback = Stream.concatEffect $ do
793793 (callback, stream) <- newCallbackStream
794794 setCallback callback
795795 return stream
src/Streamly/Internal/Data/Stream/Extra.hs+3−4
@@ -25,7 +25,6 @@ import qualified Data.Map.Strict as Map
2525import qualified Data.Set as Set
2626import qualified Streamly.Data.Fold as Fold
2727import qualified Streamly.Data.Stream as Stream
28−import qualified Streamly.Internal.Data.Stream as Stream (concatM)
2928import qualified Streamly.Internal.Data.Stream.StreamD as D
3029
3130-- $setup
@@ -79,7 +78,7 @@ toMap =
7978joinInnerMap :: (Monad m, Ord k) =>
8079 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, b)
8180joinInnerMap s1 s2 =
82− Stream.concatM $ do
81+ Stream.concatEffect $ do
8382 km <- toMap s2
8483 pure $ Stream.mapMaybe (joinAB km) s1
8584
@@ -101,7 +100,7 @@ joinInnerMap s1 s2 =
101100joinLeftMap :: (Ord k, Monad m) =>
102101 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, Maybe b)
103102joinLeftMap s1 s2 =
104− Stream.concatM $ do
103+ Stream.concatEffect $ do
105104 km <- toMap s2
106105 return $ fmap (joinAB km) s1
107106
@@ -128,7 +127,7 @@ joinOuterMap ::
128127 (Ord k, MonadIO m) =>
129128 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, Maybe a, Maybe b)
130129joinOuterMap s1 s2 =
131− Stream.concatM $ do
130+ Stream.concatEffect $ do
132131 km1 <- kvFold s1
133132 km2 <- kvFold s2
134133