on master help sign in
Rename concatM to concatEffect and expose it
ac2ee38Harendra Kumar
benchmark/Streamly/Benchmark/Data/Stream/Expand.hs+1−1
@@ -410,7 +410,7 @@ o_1_space_monad value =
410-- new prime we keep appending a division filter for all the future numbers.
410-- new prime we keep appending a division filter for all the future numbers.
411{-# INLINE sieve #-}
411{-# INLINE sieve #-}
412sieve :: Monad m => Stream m Int -> Stream m Int
412sieve :: Monad m => Stream m Int -> Stream m Int
413−sieve s = S.concatM $ do
413+sieve s = S.concatEffect $ do
414 r <- S.uncons s
414 r <- S.uncons s
415 case r of
415 case r of
416 Just (prime, rest) ->
416 Just (prime, rest) ->
benchmark/Streamly/Benchmark/Data/Stream/Lift.hs+2−2
@@ -96,7 +96,7 @@ iterateStateIO n = do
96
96
97{-# INLINE iterateStateT #-}
97{-# INLINE iterateStateT #-}
98iterateStateT :: Int -> Stream (StateT Int IO) Int
98iterateStateT :: Int -> Stream (StateT Int IO) Int
99−iterateStateT n = Stream.concatM $ do
99+iterateStateT n = Stream.concatEffect $ do
100 x <- get
100 x <- get
101 if x > n
101 if x > n
102 then do
102 then do
@@ -109,7 +109,7 @@ iterateStateT n = Stream.concatM $ do
109iterateState :: Monad m =>
109iterateState :: Monad m =>
110 Int
110 Int
111 -> Stream (StateT Int m) Int
111 -> Stream (StateT Int m) Int
112−iterateState n = Stream.concatM $ do
112+iterateState n = Stream.concatEffect $ do
113 x <- get
113 x <- get
114 if x > n
114 if x > n
115 then do
115 then do
core/src/Streamly/Data/Stream.hs+1
@@ -401,6 +401,7 @@ module Streamly.Data.Stream
401 -- > filter p m = S.concatMap (\x -> if p x then S.fromPure x else S.nil) m
401 -- > filter p m = S.concatMap (\x -> if p x then S.fromPure x else S.nil) m
402 --
402 --
403
403
404+ , concatEffect
404 , concatMapWith
405 , concatMapWith
405 , concatMap
406 , concatMap
406 , concatMapM
407 , concatMapM
core/src/Streamly/Internal/Data/Stream/Bottom.hs+8−7
@@ -52,7 +52,7 @@ module Streamly.Internal.Data.Stream.Bottom
52 , reverse'
52 , reverse'
53
53
54 -- * Expand
54 -- * Expand
55− , concatM
55+ , concatEffect
56 , concatMapM
56 , concatMapM
57 , concatMap
57 , concatMap
58
58
@@ -580,20 +580,21 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
580concatMap ::Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
580concatMap ::Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
581concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
581concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
582
582
583+-- >>> concatEffect = Stream.concat . lift -- requires (MonadTrans t)
584+-- >>> concatEffect = join . lift -- requires (MonadTrans t, Monad (Stream m))
585+
583-- | Given a stream value in the underlying monad, lift and join the underlying
586-- | Given a stream value in the underlying monad, lift and join the underlying
584-- monad with the stream monad.
587-- monad with the stream monad.
585--
588--
586−-- >>> concatM = Stream.concat . Stream.fromEffect
589+-- >>> concatEffect = Stream.concat . Stream.fromEffect
587−-- >>> concatM = Stream.concat . lift -- requires (MonadTrans t)
588−-- >>> concatM = join . lift -- requires (MonadTrans t, Monad (Stream m))
589--
590--
590-- See also: 'concat', 'sequence'
591-- See also: 'concat', 'sequence'
591--
592--
592-- /Internal/
593-- /Internal/
593--
594--
594−{-# INLINE concatM #-}
595+{-# INLINE concatEffect #-}
595−concatM :: Monad m => m (Stream m a) -> Stream m a
596+concatEffect :: Monad m => m (Stream m a) -> Stream m a
596−concatM generator = concatMapM (\() -> generator) (fromPure ())
597+concatEffect generator = concatMapM (\() -> generator) (fromPure ())
597
598
598-- XXX Need a more intuitive name, and need to reconcile the names
599-- XXX Need a more intuitive name, and need to reconcile the names
599-- foldMany/fold/parse/parseMany/parseManyPost etc.
600-- 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
92 -- the binary append operation to append many streams.
92 -- the binary append operation to append many streams.
93 , concatMapM
93 , concatMapM
94 , concatMap
94 , concatMap
95− , concatM
95+ , concatEffect
96 , concat
96 , concat
97
97
98 -- * ConcatMapWith
98 -- * ConcatMapWith
@@ -128,7 +128,7 @@ where
128#include "inline.hs"
128#include "inline.hs"
129
129
130import Streamly.Internal.Data.Stream.Bottom
130import Streamly.Internal.Data.Stream.Bottom
131− ( concatM, concatMapM, concatMap, smapM, fromPure, fromEffect
131+ ( concatEffect, concatMapM, concatMap, smapM, fromPure, fromEffect
132 , zipWith, zipWithM)
132 , zipWith, zipWithM)
133import Streamly.Internal.Data.Stream.Type
133import Streamly.Internal.Data.Stream.Type
134 ( Stream, fromStreamD, fromStreamK, toStreamD, toStreamK
134 ( 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
252 -- XXX Is there a better way to perform some action at the end of a loop
252 -- XXX Is there a better way to perform some action at the end of a loop
253 -- iteration?
253 -- iteration?
254 CrossStream (Stream.fromEffect $ put False)
254 CrossStream (Stream.fromEffect $ put False)
255− let final = Stream.concatM $ do
255+ let final = Stream.concatEffect $ do
256 r <- get
256 r <- get
257 if r
257 if r
258 then pure Stream.nil
258 then pure Stream.nil
@@ -300,7 +300,7 @@ joinOuter :: MonadIO m =>
300 -> Stream m b
300 -> Stream m b
301 -> Stream m (Maybe a, Maybe b)
301 -> Stream m (Maybe a, Maybe b)
302joinOuter eq s1 s =
302joinOuter eq s1 s =
303− Stream.concatM $ do
303+ Stream.concatEffect $ do
304 inputArr <- Array.fromStream s
304 inputArr <- Array.fromStream s
305 let len = Array.length inputArr
305 let len = Array.length inputArr
306 foundArr <-
306 foundArr <-
@@ -331,7 +331,7 @@ joinOuter eq s1 s =
331 -- XXX Is there a better way to perform some action at the end of a loop
331 -- XXX Is there a better way to perform some action at the end of a loop
332 -- iteration?
332 -- iteration?
333 CrossStream (Stream.fromEffect $ put False)
333 CrossStream (Stream.fromEffect $ put False)
334− let final = Stream.concatM $ do
334+ let final = Stream.concatEffect $ do
335 r <- get
335 r <- get
336 if r
336 if r
337 then pure Stream.nil
337 then pure Stream.nil
@@ -398,7 +398,7 @@ mergeOuterJoin _eq _s1 _s2 = undefined
398intersectBy :: Monad m =>
398intersectBy :: Monad m =>
399 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
399 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
400intersectBy eq s1 s2 =
400intersectBy eq s1 s2 =
401− Stream.concatM
401+ Stream.concatEffect
402 $ do
402 $ do
403 -- This may work well when s2 is small
403 -- This may work well when s2 is small
404 xs <- Stream.fold Fold.toListRev $ Stream.uniqBy eq s2
404 xs <- Stream.fold Fold.toListRev $ Stream.uniqBy eq s2
@@ -447,7 +447,7 @@ intersectBySorted eq s1 =
447differenceBy :: (Monad m) =>
447differenceBy :: (Monad m) =>
448 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
448 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
449differenceBy eq s1 s2 =
449differenceBy eq s1 s2 =
450− Stream.concatM
450+ Stream.concatEffect
451 $ do
451 $ do
452 -- This may work well if s1 is small
452 -- This may work well if s1 is small
453 -- If s1 is big we can go through s1, deleting elements from s2 and
453 -- If s1 is big we can go through s1, deleting elements from s2 and
@@ -492,7 +492,7 @@ mergeDifferenceBy _eq _s1 _s2 = undefined
492unionBy :: MonadIO m =>
492unionBy :: MonadIO m =>
493 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
493 (a -> a -> Bool) -> Stream m a -> Stream m a -> Stream m a
494unionBy eq s1 s2 =
494unionBy eq s1 s2 =
495− Stream.concatM
495+ Stream.concatEffect
496 $ do
496 $ do
497 xs <- Stream.fold Fold.toList s2
497 xs <- Stream.fold Fold.toList s2
498 -- XXX we can use postscanlMAfter' instead of IORef
498 -- XXX we can use postscanlMAfter' instead of IORef
@@ -500,7 +500,7 @@ unionBy eq s1 s2 =
500 let f x = do
500 let f x = do
501 liftIO $ modifyIORef' ref (List.deleteBy eq x)
501 liftIO $ modifyIORef' ref (List.deleteBy eq x)
502 return x
502 return x
503− s3 = Stream.concatM
503+ s3 = Stream.concatEffect
504 $ do
504 $ do
505 xs1 <- liftIO $ readIORef ref
505 xs1 <- liftIO $ readIORef ref
506 return $ Stream.fromList xs1
506 return $ Stream.fromList xs1
src/Streamly/Internal/Data/Stream/Concurrent.hs+1−1
@@ -789,7 +789,7 @@ newCallbackStream = do
789--
789--
790{-# INLINE fromCallback #-}
790{-# INLINE fromCallback #-}
791fromCallback :: MonadAsync m => ((a -> m ()) -> m ()) -> Stream m a
791fromCallback :: MonadAsync m => ((a -> m ()) -> m ()) -> Stream m a
792−fromCallback setCallback = Stream.concatM $ do
792+fromCallback setCallback = Stream.concatEffect $ do
793 (callback, stream) <- newCallbackStream
793 (callback, stream) <- newCallbackStream
794 setCallback callback
794 setCallback callback
795 return stream
795 return stream
src/Streamly/Internal/Data/Stream/Extra.hs+3−4
@@ -25,7 +25,6 @@ import qualified Data.Map.Strict as Map
25import qualified Data.Set as Set
25import qualified Data.Set as Set
26import qualified Streamly.Data.Fold as Fold
26import qualified Streamly.Data.Fold as Fold
27import qualified Streamly.Data.Stream as Stream
27import qualified Streamly.Data.Stream as Stream
28−import qualified Streamly.Internal.Data.Stream as Stream (concatM)
29import qualified Streamly.Internal.Data.Stream.StreamD as D
28import qualified Streamly.Internal.Data.Stream.StreamD as D
30
29
31-- $setup
30-- $setup
@@ -79,7 +78,7 @@ toMap =
79joinInnerMap :: (Monad m, Ord k) =>
78joinInnerMap :: (Monad m, Ord k) =>
80 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, b)
79 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, b)
81joinInnerMap s1 s2 =
80joinInnerMap s1 s2 =
82− Stream.concatM $ do
81+ Stream.concatEffect $ do
83 km <- toMap s2
82 km <- toMap s2
84 pure $ Stream.mapMaybe (joinAB km) s1
83 pure $ Stream.mapMaybe (joinAB km) s1
85
84
@@ -101,7 +100,7 @@ joinInnerMap s1 s2 =
101joinLeftMap :: (Ord k, Monad m) =>
100joinLeftMap :: (Ord k, Monad m) =>
102 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, Maybe b)
101 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, a, Maybe b)
103joinLeftMap s1 s2 =
102joinLeftMap s1 s2 =
104− Stream.concatM $ do
103+ Stream.concatEffect $ do
105 km <- toMap s2
104 km <- toMap s2
106 return $ fmap (joinAB km) s1
105 return $ fmap (joinAB km) s1
107
106
@@ -128,7 +127,7 @@ joinOuterMap ::
128 (Ord k, MonadIO m) =>
127 (Ord k, MonadIO m) =>
129 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, Maybe a, Maybe b)
128 Stream m (k, a) -> Stream m (k, b) -> Stream m (k, Maybe a, Maybe b)
130joinOuterMap s1 s2 =
129joinOuterMap s1 s2 =
131− Stream.concatM $ do
130+ Stream.concatEffect $ do
132 km1 <- kvFold s1
131 km1 <- kvFold s1
133 km2 <- kvFold s2
132 km2 <- kvFold s2
134
133