on master help sign in
Rename Streamly.Prelude.yieldM to fromEffect.
70faf01Pranay Sashank
Changelog.md+1
@@ -93,6 +93,7 @@
93* In `Streamly.Prelude` the following functions have been renamed:
93* In `Streamly.Prelude` the following functions have been renamed:
94 * `concatUnfold` to `unfoldMany`
94 * `concatUnfold` to `unfoldMany`
95 * `yield` to `fromPure`
95 * `yield` to `fromPure`
96+ * `yieldM` to `fromEffect`
96* The following encoding/decoding routines have been renamed:
97* The following encoding/decoding routines have been renamed:
97 * `encodeUtf8Lax` to `encodeUtf8`
98 * `encodeUtf8Lax` to `encodeUtf8`
98 * `encodeLatin1Lax` to `encodeLatin1`
99 * `encodeLatin1Lax` to `encodeLatin1`
benchmark/Streamly/Benchmark/Data/Stream/StreamDK.hs+1−1
@@ -108,7 +108,7 @@ sourceFoldMapWith n = SP.foldMapWith S.serial S.fromPure [n..n+value]
108
108
109{-# INLINE sourceFoldMapWithM #-}
109{-# INLINE sourceFoldMapWithM #-}
110sourceFoldMapWithM :: Monad m => Int -> Stream m Int
110sourceFoldMapWithM :: Monad m => Int -> Stream m Int
111−sourceFoldMapWithM n = SP.foldMapWith S.serial (S.yieldM . return) [n..n+value]
111+sourceFoldMapWithM n = SP.foldMapWith S.serial (S.fromEffect . return) [n..n+value]
112-}
112-}
113
113
114-------------------------------------------------------------------------------
114-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+2−2
@@ -159,7 +159,7 @@ concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.fromPure
159{-# INLINE concatMapFoldableSerialM #-}
159{-# INLINE concatMapFoldableSerialM #-}
160concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
160concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
161concatMapFoldableSerialM streamLen n =
161concatMapFoldableSerialM streamLen n =
162− concatMapFoldableWith S.serial (S.yieldM . return) [n..n+streamLen]
162+ concatMapFoldableWith S.serial (S.fromEffect . return) [n..n+streamLen]
163
163
164-------------------------------------------------------------------------------
164-------------------------------------------------------------------------------
165-- Elimination
165-- Elimination
@@ -446,7 +446,7 @@ inspect $ hasNoTypeClasses 'concatMapRepl
446sourceConcatMapId :: Monad m
446sourceConcatMapId :: Monad m
447 => Int -> Int -> Stream m (Stream m Int)
447 => Int -> Int -> Stream m (Stream m Int)
448sourceConcatMapId val n =
448sourceConcatMapId val n =
449− S.fromFoldable $ fmap (S.yieldM . return) [n..n+val]
449+ S.fromFoldable $ fmap (S.fromEffect . return) [n..n+val]
450
450
451{-# INLINE concatMapBySerial #-}
451{-# INLINE concatMapBySerial #-}
452concatMapBySerial :: Int -> Int -> Int -> IO ()
452concatMapBySerial :: Int -> Int -> Int -> IO ()
benchmark/Streamly/Benchmark/Prelude/Serial/Exceptions.hs+1−1
@@ -51,7 +51,7 @@ readWriteOnExceptionStream inh devNull =
51-- | Send the file contents to /dev/null with exception handling
51-- | Send the file contents to /dev/null with exception handling
52readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
52readWriteHandleExceptionStream :: Handle -> Handle -> IO ()
53readWriteHandleExceptionStream inh devNull =
53readWriteHandleExceptionStream inh devNull =
54− let handler (_e :: SomeException) = S.yieldM (hClose inh >> return 10)
54+ let handler (_e :: SomeException) = S.fromEffect (hClose inh >> return 10)
55 readEx = S.handle handler (S.unfold FH.read inh)
55 readEx = S.handle handler (S.unfold FH.read inh)
56 in S.fold (FH.write devNull) $ readEx
56 in S.fold (FH.write devNull) $ readEx
57
57
benchmark/lib/Streamly/Benchmark/Prelude.hs+3−3
@@ -323,12 +323,12 @@ sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.fromPure
323sourceFoldMapWithM :: (S.IsStream t, Monad m, Semigroup (t m Int))
323sourceFoldMapWithM :: (S.IsStream t, Monad m, Semigroup (t m Int))
324 => Int -> Int -> t m Int
324 => Int -> Int -> t m Int
325sourceFoldMapWithM value n =
325sourceFoldMapWithM value n =
326− S.concatMapFoldableWith (<>) (S.yieldM . return) [n..n+value]
326+ S.concatMapFoldableWith (<>) (S.fromEffect . return) [n..n+value]
327
327
328{-# INLINE sourceFoldMapM #-}
328{-# INLINE sourceFoldMapM #-}
329sourceFoldMapM :: (S.IsStream t, Monad m, Monoid (t m Int))
329sourceFoldMapM :: (S.IsStream t, Monad m, Monoid (t m Int))
330 => Int -> Int -> t m Int
330 => Int -> Int -> t m Int
331−sourceFoldMapM value n = F.foldMap (S.yieldM . return) [n..n+value]
331+sourceFoldMapM value n = F.foldMap (S.fromEffect . return) [n..n+value]
332
332
333-------------------------------------------------------------------------------
333-------------------------------------------------------------------------------
334-- Concat
334-- Concat
@@ -338,7 +338,7 @@ sourceFoldMapM value n = F.foldMap (S.yieldM . return) [n..n+value]
338sourceConcatMapId :: (S.IsStream t, Monad m)
338sourceConcatMapId :: (S.IsStream t, Monad m)
339 => Int -> Int -> t m (t m Int)
339 => Int -> Int -> t m (t m Int)
340sourceConcatMapId value n =
340sourceConcatMapId value n =
341− S.fromFoldable $ fmap (S.yieldM . return) [n..n+value]
341+ S.fromFoldable $ fmap (S.fromEffect . return) [n..n+value]
342
342
343-- concatMapWith
343-- concatMapWith
344
344
docs/Overview.md+3−3
@@ -154,7 +154,7 @@ import qualified Streamly.Prelude as S
154import Control.Concurrent (threadDelay)
154import Control.Concurrent (threadDelay)
155
155
156main = S.toList $ S.fromParallel $ foldMap delay [1..10]
156main = S.toList $ S.fromParallel $ foldMap delay [1..10]
157− where delay n = S.yieldM $ threadDelay (n * 1000000) >> print n
157+ where delay n = S.fromEffect $ threadDelay (n * 1000000) >> print n
158```
158```
159
159
160Streams can be combined together in many ways. We provide some examples
160Streams can be combined together in many ways. We provide some examples
@@ -165,7 +165,7 @@ function in the examples to demonstrate the concurrency aspects:
165import qualified Streamly.Prelude as S
165import qualified Streamly.Prelude as S
166import Control.Concurrent
166import Control.Concurrent
167
167
168−delay n = S.yieldM $ do
168+delay n = S.fromEffect $ do
169 threadDelay (n * 1000000)
169 threadDelay (n * 1000000)
170 tid <- myThreadId
170 tid <- myThreadId
171 putStrLn (show tid ++ ": Delay " ++ show n)
171 putStrLn (show tid ++ ": Delay " ++ show n)
@@ -202,7 +202,7 @@ import qualified Streamly.Prelude as S
202loops = do
202loops = do
203 x <- S.fromFoldable [1,2]
203 x <- S.fromFoldable [1,2]
204 y <- S.fromFoldable [3,4]
204 y <- S.fromFoldable [3,4]
205− S.yieldM $ putStrLn $ show (x, y)
205+ S.fromEffect $ putStrLn $ show (x, y)
206
206
207main = S.drain loops
207main = S.drain loops
208```
208```
docs/streamly-vs-async.md+3−3
@@ -30,7 +30,7 @@ monad.
30
30
31You can write all of your program in a streamly monad and use the full power of
31You can write all of your program in a streamly monad and use the full power of
32the library. Streamly can be used as a direct replacement of the IO monad with
32the library. Streamly can be used as a direct replacement of the IO monad with
33−no loss of performance, and no change in code except using `liftIO` or `yieldM`
33+no loss of performance, and no change in code except using `liftIO` or `fromEffect`
34to run any IO actions. Streamly IO monads (e.g. `SerialT IO`) are just a
34to run any IO actions. Streamly IO monads (e.g. `SerialT IO`) are just a
35generalization of the IO monad with non-deterministic composition of streams
35generalization of the IO monad with non-deterministic composition of streams
36added on top.
36added on top.
@@ -98,7 +98,7 @@ function:
98
98
99```haskell
99```haskell
100 tuples <- S.toList $ fromZipAsync $
100 tuples <- S.toList $ fromZipAsync $
101− (,) <$> S.yieldM (getURLString 1) <*> S.yieldM (getURLText 2)
101+ (,) <$> S.fromEffect (getURLString 1) <*> S.fromEffect (getURLText 2)
102```
102```
103
103
104### race
104### race
@@ -166,7 +166,7 @@ You can map a monadic action to a `Foldable` container to convert it into a
166stream and at the same time fold it:
166stream and at the same time fold it:
167
167
168```haskell
168```haskell
169− urls <- S.toList $ fromAhead $ foldMap (S.yieldM . getURL) [1..3]
169+ urls <- S.toList $ fromAhead $ foldMap (S.fromEffect . getURL) [1..3]
170```
170```
171
171
172### replicateConcurrently
172### replicateConcurrently
src/Streamly/Internal/Data/Stream/Ahead.hs+7−7
@@ -136,7 +136,7 @@ import Prelude hiding (map)
136-- XXX It may be a good idea to increment sequence numbers for each yield,
136-- XXX It may be a good idea to increment sequence numbers for each yield,
137-- currently a stream on the left side of the expression may yield many
137-- currently a stream on the left side of the expression may yield many
138-- elements with the same sequene number. We can then use the seq number to
138-- elements with the same sequene number. We can then use the seq number to
139−-- enforce yieldMax and yieldLImit as well.
139+-- enforce fromEffectax and yieldLImit as well.
140
140
141-- Invariants:
141-- Invariants:
142--
142--
@@ -620,8 +620,8 @@ infixr 6 `ahead`
620-- are evaluated:
620-- are evaluated:
621--
621--
622-- >>> import Streamly.Prelude (ahead)
622-- >>> import Streamly.Prelude (ahead)
623−-- >>> stream1 = Stream.yieldM (delay 4) :: SerialT IO Int
623+-- >>> stream1 = Stream.fromEffect (delay 4) :: SerialT IO Int
624−-- >>> stream2 = Stream.yieldM (delay 2) :: SerialT IO Int
624+-- >>> stream2 = Stream.fromEffect (delay 2) :: SerialT IO Int
625-- >>> Stream.toList $ stream1 `ahead` stream2 :: IO [Int]
625-- >>> Stream.toList $ stream1 `ahead` stream2 :: IO [Int]
626-- 2 sec
626-- 2 sec
627-- 4 sec
627-- 4 sec
@@ -630,7 +630,7 @@ infixr 6 `ahead`
630-- Multiple streams can be combined. With enough threads, all of them can be
630-- Multiple streams can be combined. With enough threads, all of them can be
631-- scheduled simultaneously:
631-- scheduled simultaneously:
632--
632--
633−-- >>> stream3 = Stream.yieldM (delay 1)
633+-- >>> stream3 = Stream.fromEffect (delay 1)
634-- >>> Stream.toList $ stream1 `ahead` stream2 `ahead` stream3
634-- >>> Stream.toList $ stream1 `ahead` stream2 `ahead` stream3
635-- 1 sec
635-- 1 sec
636-- 2 sec
636-- 2 sec
@@ -674,7 +674,7 @@ ahead m1 m2 = mkStream $ \st yld sng stp ->
674{-# INLINE consMAhead #-}
674{-# INLINE consMAhead #-}
675{-# SPECIALIZE consMAhead :: IO a -> AheadT IO a -> AheadT IO a #-}
675{-# SPECIALIZE consMAhead :: IO a -> AheadT IO a -> AheadT IO a #-}
676consMAhead :: MonadAsync m => m a -> AheadT m a -> AheadT m a
676consMAhead :: MonadAsync m => m a -> AheadT m a -> AheadT m a
677−consMAhead m r = fromStream $ K.yieldM m `ahead` (toStream r)
677+consMAhead m r = fromStream $ K.fromEffect m `ahead` (toStream r)
678
678
679------------------------------------------------------------------------------
679------------------------------------------------------------------------------
680-- AheadT
680-- AheadT
@@ -694,7 +694,7 @@ consMAhead m r = fromStream $ K.yieldM m `ahead` (toStream r)
694-- >>> :{
694-- >>> :{
695-- Stream.toList $ Stream.fromAhead $ do
695-- Stream.toList $ Stream.fromAhead $ do
696-- x <- Stream.fromList [2,1] -- foreach x in stream
696-- x <- Stream.fromList [2,1] -- foreach x in stream
697−-- Stream.yieldM $ delay x
697+-- Stream.fromEffect $ delay x
698-- :}
698-- :}
699-- 1 sec
699-- 1 sec
700-- 2 sec
700-- 2 sec
@@ -707,7 +707,7 @@ consMAhead m r = fromStream $ K.yieldM m `ahead` (toStream r)
707-- Stream.toList $ Stream.fromAhead $ do
707-- Stream.toList $ Stream.fromAhead $ do
708-- x <- Stream.fromList [1,2] -- foreach x in stream
708-- x <- Stream.fromList [1,2] -- foreach x in stream
709-- y <- Stream.fromList [2,4] -- foreach y in stream
709-- y <- Stream.fromList [2,4] -- foreach y in stream
710−-- Stream.yieldM $ delay (x + y)
710+-- Stream.fromEffect $ delay (x + y)
711-- :}
711-- :}
712-- 3 sec
712-- 3 sec
713-- 4 sec
713-- 4 sec
src/Streamly/Internal/Data/Stream/Async.hs+10−10
@@ -657,8 +657,8 @@ infixr 6 `async`
657-- outputs from both are used as they arrive:
657-- outputs from both are used as they arrive:
658--
658--
659-- >>> import Streamly.Prelude (async)
659-- >>> import Streamly.Prelude (async)
660−-- >>> stream1 = Stream.yieldM (delay 4)
660+-- >>> stream1 = Stream.fromEffect (delay 4)
661−-- >>> stream2 = Stream.yieldM (delay 2)
661+-- >>> stream2 = Stream.fromEffect (delay 2)
662-- >>> Stream.toList $ stream1 `async` stream2
662-- >>> Stream.toList $ stream1 `async` stream2
663-- 2 sec
663-- 2 sec
664-- 4 sec
664-- 4 sec
@@ -667,7 +667,7 @@ infixr 6 `async`
667-- Multiple streams can be combined. With enough threads, all of them can be
667-- Multiple streams can be combined. With enough threads, all of them can be
668-- scheduled simultaneously:
668-- scheduled simultaneously:
669--
669--
670−-- >>> stream3 = Stream.yieldM (delay 1)
670+-- >>> stream3 = Stream.fromEffect (delay 1)
671-- >>> Stream.toList $ stream1 `async` stream2 `async` stream3
671-- >>> Stream.toList $ stream1 `async` stream2 `async` stream3
672-- ...
672-- ...
673-- [1,2,4]
673-- [1,2,4]
@@ -735,7 +735,7 @@ async = joinStreamVarAsync AsyncVar
735{-# INLINE consMAsync #-}
735{-# INLINE consMAsync #-}
736{-# SPECIALIZE consMAsync :: IO a -> AsyncT IO a -> AsyncT IO a #-}
736{-# SPECIALIZE consMAsync :: IO a -> AsyncT IO a -> AsyncT IO a #-}
737consMAsync :: MonadAsync m => m a -> AsyncT m a -> AsyncT m a
737consMAsync :: MonadAsync m => m a -> AsyncT m a -> AsyncT m a
738−consMAsync m r = fromStream $ K.yieldM m `async` (toStream r)
738+consMAsync m r = fromStream $ K.fromEffect m `async` (toStream r)
739
739
740------------------------------------------------------------------------------
740------------------------------------------------------------------------------
741-- AsyncT
741-- AsyncT
@@ -755,7 +755,7 @@ consMAsync m r = fromStream $ K.yieldM m `async` (toStream r)
755-- >>> :{
755-- >>> :{
756-- Stream.toList $ Stream.fromAsync $ do
756-- Stream.toList $ Stream.fromAsync $ do
757-- x <- Stream.fromList [2,1] -- foreach x in stream
757-- x <- Stream.fromList [2,1] -- foreach x in stream
758−-- Stream.yieldM $ delay x
758+-- Stream.fromEffect $ delay x
759-- :}
759-- :}
760-- 1 sec
760-- 1 sec
761-- 2 sec
761-- 2 sec
@@ -768,7 +768,7 @@ consMAsync m r = fromStream $ K.yieldM m `async` (toStream r)
768-- Stream.toList $ Stream.fromAsync $ do
768-- Stream.toList $ Stream.fromAsync $ do
769-- x <- Stream.fromList [1,2] -- foreach x in stream
769-- x <- Stream.fromList [1,2] -- foreach x in stream
770-- y <- Stream.fromList [2,4] -- foreach y in stream
770-- y <- Stream.fromList [2,4] -- foreach y in stream
771−-- Stream.yieldM $ delay (x + y)
771+-- Stream.fromEffect $ delay (x + y)
772-- :}
772-- :}
773-- 3 sec
773-- 3 sec
774-- 4 sec
774-- 4 sec
@@ -880,7 +880,7 @@ MONAD_COMMON_INSTANCES(AsyncT, MONADPARALLEL)
880{-# INLINE consMWAsync #-}
880{-# INLINE consMWAsync #-}
881{-# SPECIALIZE consMWAsync :: IO a -> WAsyncT IO a -> WAsyncT IO a #-}
881{-# SPECIALIZE consMWAsync :: IO a -> WAsyncT IO a -> WAsyncT IO a #-}
882consMWAsync :: MonadAsync m => m a -> WAsyncT m a -> WAsyncT m a
882consMWAsync :: MonadAsync m => m a -> WAsyncT m a -> WAsyncT m a
883−consMWAsync m r = fromStream $ K.yieldM m `wAsync` (toStream r)
883+consMWAsync m r = fromStream $ K.fromEffect m `wAsync` (toStream r)
884
884
885infixr 6 `wAsync`
885infixr 6 `wAsync`
886
886
@@ -968,7 +968,7 @@ wAsync = joinStreamVarAsync WAsyncVar
968-- >>> :{
968-- >>> :{
969-- Stream.toList $ Stream.fromWAsync $ do
969-- Stream.toList $ Stream.fromWAsync $ do
970-- x <- Stream.fromList [2,1] -- foreach x in stream
970-- x <- Stream.fromList [2,1] -- foreach x in stream
971−-- Stream.yieldM $ delay x
971+-- Stream.fromEffect $ delay x
972-- :}
972-- :}
973-- 1 sec
973-- 1 sec
974-- 2 sec
974-- 2 sec
@@ -981,7 +981,7 @@ wAsync = joinStreamVarAsync WAsyncVar
981-- Stream.toList $ Stream.fromWAsync $ do
981-- Stream.toList $ Stream.fromWAsync $ do
982-- x <- Stream.fromList [1,2] -- foreach x in stream
982-- x <- Stream.fromList [1,2] -- foreach x in stream
983-- y <- Stream.fromList [2,4] -- foreach y in stream
983-- y <- Stream.fromList [2,4] -- foreach y in stream
984−-- Stream.yieldM $ delay (x + y)
984+-- Stream.fromEffect $ delay (x + y)
985-- :}
985-- :}
986-- 3 sec
986-- 3 sec
987-- 4 sec
987-- 4 sec
@@ -1071,7 +1071,7 @@ wAsync = joinStreamVarAsync WAsyncVar
1071-- @
1071-- @
1072-- main = S.'drain' . S.'fromWAsync' $ do
1072-- main = S.'drain' . S.'fromWAsync' $ do
1073-- n <- return 3 \<\> return 2 \<\> return 1
1073-- n <- return 3 \<\> return 2 \<\> return 1
1074−-- S.yieldM $ do
1074+-- S.fromEffect $ do
1075-- threadDelay (n * 1000000)
1075-- threadDelay (n * 1000000)
1076-- myThreadId >>= \\tid -> putStrLn (show tid ++ ": Delay " ++ show n)
1076-- myThreadId >>= \\tid -> putStrLn (show tid ++ ": Delay " ++ show n)
1077-- @
1077-- @
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+22−12
@@ -15,7 +15,7 @@ module Streamly.Internal.Data.Stream.IsStream.Common
15 (
15 (
16 -- * Generation
16 -- * Generation
17 fromPure
17 fromPure
18− , yieldM
18+ , fromEffect
19 , repeatM
19 , repeatM
20 , timesWith
20 , timesWith
21 , absTimesWith
21 , absTimesWith
@@ -47,6 +47,7 @@ module Streamly.Internal.Data.Stream.IsStream.Common
47
47
48 -- * Deprecated
48 -- * Deprecated
49 , yield
49 , yield
50+ , yieldM
50 )
51 )
51where
52where
52
53
@@ -91,7 +92,7 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
91-- Generation
92-- Generation
92------------------------------------------------------------------------------
93------------------------------------------------------------------------------
93
94
94−-- Faster than yieldM because there is no bind.
95+-- Faster than fromEffect because there is no bind.
95--
96--
96-- |
97-- |
97-- @
98-- @
@@ -104,7 +105,7 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
104--
105--
105-- @
106-- @
106-- fromPure = pure
107-- fromPure = pure
107−-- fromPure = yieldM . pure
108+-- fromPure = fromEffect . pure
108-- @
109-- @
109--
110--
110-- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
111-- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
@@ -120,26 +121,27 @@ fromPure = K.fromPure
120
121
121-- |
122-- |
122-- @
123-- @
123−-- yieldM m = m \`consM` nil
124+-- fromEffect m = m \`consM` nil
124-- @
125-- @
125--
126--
126-- Create a singleton stream from a monadic action.
127-- Create a singleton stream from a monadic action.
127--
128--
128-- @
129-- @
129−-- > Stream.toList $ Stream.yieldM getLine
130+-- > Stream.toList $ Stream.fromEffect getLine
130-- hello
131-- hello
131-- ["hello"]
132-- ["hello"]
132-- @
133-- @
133--
134--
134−-- @since 0.4.0
135+-- /Since: 0.8.0 (Renamed yieldM to fromEffect)/
136+--
135−{-# INLINE yieldM #-}
137+{-# INLINE fromEffect #-}
136−yieldM :: (Monad m, IsStream t) => m a -> t m a
138+fromEffect :: (Monad m, IsStream t) => m a -> t m a
137−yieldM = K.yieldM
139+fromEffect = K.fromEffect
138
140
139-- |
141-- |
140-- @
142-- @
141-- repeatM = fix . consM
143-- repeatM = fix . consM
142−-- repeatM = cycle1 . yieldM
144+-- repeatM = cycle1 . fromEffect
143-- @
145-- @
144--
146--
145-- Generate a stream by repeatedly executing a monadic action forever.
147-- Generate a stream by repeatedly executing a monadic action forever.
@@ -477,7 +479,7 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
477-- monad with the stream monad.
479-- monad with the stream monad.
478--
480--
479-- @
481-- @
480−-- concatM = concat . yieldM
482+-- concatM = concat . fromEffect
481-- concatM = concat . lift -- requires @(MonadTrans t)@
483-- concatM = concat . lift -- requires @(MonadTrans t)@
482-- concatM = join . lift -- requires @(MonadTrans t@, @Monad (t m))@
484-- concatM = join . lift -- requires @(MonadTrans t@, @Monad (t m))@
483-- @
485-- @
@@ -550,10 +552,18 @@ splitOnSeq
550 => Array a -> Fold m a b -> t m a -> t m b
552 => Array a -> Fold m a b -> t m a -> t m b
551splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m)
553splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m)
552
554
553−-- | Same as 'yield'
555+-- | Same as 'fromPure'
554--
556--
555-- @since 0.4.0
557-- @since 0.4.0
556{-# DEPRECATED yield "Please use fromPure instead." #-}
558{-# DEPRECATED yield "Please use fromPure instead." #-}
557{-# INLINE yield #-}
559{-# INLINE yield #-}
558yield :: IsStream t => a -> t m a
560yield :: IsStream t => a -> t m a
559yield = fromPure
561yield = fromPure
562+
563+-- | Same as 'fromEffect'
564+--
565+-- @since 0.4.0
566+{-# DEPRECATED yieldM "Please use fromEffect instead." #-}
567+{-# INLINE yieldM #-}
568+yieldM :: (Monad m, IsStream t) => m a -> t m a
569+yieldM = fromEffect
src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+4−4
@@ -161,7 +161,7 @@ where
161import Streamly.Internal.Data.Stream.Ahead (ahead)
161import Streamly.Internal.Data.Stream.Ahead (ahead)
162import Streamly.Internal.Data.Stream.Async (async, wAsync)
162import Streamly.Internal.Data.Stream.Async (async, wAsync)
163import Streamly.Internal.Data.Stream.IsStream.Common
163import Streamly.Internal.Data.Stream.IsStream.Common
164− (concatM, concatMapM, concatMap, smapM, fromPure, yieldM)
164+ (concatM, concatMapM, concatMap, smapM, fromPure, fromEffect)
165import Streamly.Internal.Data.Stream.Parallel (parallel)
165import Streamly.Internal.Data.Stream.Parallel (parallel)
166import Streamly.Internal.Data.Stream.Prelude
166import Streamly.Internal.Data.Stream.Prelude
167 ( concatFoldableWith, concatMapFoldableWith
167 ( concatFoldableWith, concatMapFoldableWith
@@ -714,7 +714,7 @@ concatPairsWith = K.concatPairsWith
714-- Note that 'iterateM' is a special case of 'iterateMapWith':
714-- Note that 'iterateM' is a special case of 'iterateMapWith':
715--
715--
716-- @
716-- @
717−-- iterateM f = iterateMapWith serial (yieldM . f) . yieldM
717+-- iterateM f = iterateMapWith serial (fromEffect . f) . fromEffect
718-- @
718-- @
719--
719--
720-- It can be used to traverse a tree structure. For example, to list a
720-- It can be used to traverse a tree structure. For example, to list a
@@ -774,7 +774,7 @@ iterateSmapMWith
774 -> t m a
774 -> t m a
775 -> t m a
775 -> t m a
776iterateSmapMWith combine f initial stream =
776iterateSmapMWith combine f initial stream =
777− concatMap (\b -> concatMapWith combine (go b) stream) (yieldM initial)
777+ concatMap (\b -> concatMapWith combine (go b) stream) (fromEffect initial)
778
778
779 where
779 where
780
780
@@ -783,7 +783,7 @@ iterateSmapMWith combine f initial stream =
783 feedback b a =
783 feedback b a =
784 concatMap
784 concatMap
785 (\(b1, s) -> concatMapWith combine (go b1) s)
785 (\(b1, s) -> concatMapWith combine (go b1) s)
786− (yieldM $ f b a)
786+ (fromEffect $ f b a)
787
787
788------------------------------------------------------------------------------
788------------------------------------------------------------------------------
789-- iterateMap - Either streams
789-- iterateMap - Either streams
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−3
@@ -36,7 +36,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
36
36
37 -- * From Values
37 -- * From Values
38 , fromPure
38 , fromPure
39− , yieldM
39+ , fromEffect
40 , repeat
40 , repeat
41 , repeatM
41 , repeatM
42 , replicate
42 , replicate
@@ -80,6 +80,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
80 -- * Deprecated
80 -- * Deprecated
81 , K.once
81 , K.once
82 , yield
82 , yield
83+ , yieldM
83 , each
84 , each
84 , fromHandle
85 , fromHandle
85 , currentTime
86 , currentTime
@@ -95,8 +96,8 @@ import Streamly.Internal.Data.SVar (MonadAsync, Rate (..))
95import Streamly.Internal.Data.Stream.IsStream.Enumeration
96import Streamly.Internal.Data.Stream.IsStream.Enumeration
96 (Enumerable(..), enumerate, enumerateTo)
97 (Enumerable(..), enumerate, enumerateTo)
97import Streamly.Internal.Data.Stream.IsStream.Common
98import Streamly.Internal.Data.Stream.IsStream.Common
98− ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, yield, yieldM
99+ ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, fromEffect
99− , repeatM)
100+ , yield, yieldM, repeatM)
100import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
101import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
101import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
102import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
102import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM))
103import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM))
src/Streamly/Internal/Data/Stream/Parallel.hs+2−2
@@ -231,7 +231,7 @@ joinStreamVarPar style ss m1 m2 = mkStream $ \st yld sng stp ->
231{-# INLINE consMParallel #-}
231{-# INLINE consMParallel #-}
232{-# SPECIALIZE consMParallel :: IO a -> ParallelT IO a -> ParallelT IO a #-}
232{-# SPECIALIZE consMParallel :: IO a -> ParallelT IO a -> ParallelT IO a #-}
233consMParallel :: MonadAsync m => m a -> ParallelT m a -> ParallelT m a
233consMParallel :: MonadAsync m => m a -> ParallelT m a -> ParallelT m a
234−consMParallel m r = fromStream $ K.yieldM m `parallel` (toStream r)
234+consMParallel m r = fromStream $ K.fromEffect m `parallel` (toStream r)
235
235
236infixr 6 `parallel`
236infixr 6 `parallel`
237
237
@@ -243,7 +243,7 @@ infixr 6 `parallel`
243-- Evaluation may block if the output buffer becomes full.
243-- Evaluation may block if the output buffer becomes full.
244--
244--
245-- >>> import Streamly.Prelude (parallel)
245-- >>> import Streamly.Prelude (parallel)
246−-- >>> stream = Stream.yieldM (delay 2) `parallel` Stream.yieldM (delay 1)
246+-- >>> stream = Stream.fromEffect (delay 2) `parallel` Stream.fromEffect (delay 1)
247-- >>> Stream.toList stream -- IO [Int]
247-- >>> Stream.toList stream -- IO [Int]
248-- 1 sec
248-- 1 sec
249-- 2 sec
249-- 2 sec
src/Streamly/Internal/Data/Stream/StreamD/Generate.hs+1−1
@@ -39,7 +39,7 @@ module Streamly.Internal.Data.Stream.StreamD.Generate
39
39
40 -- * From Values
40 -- * From Values
41 , fromPure
41 , fromPure
42− , yieldM
42+ , fromEffect
43 , repeat
43 , repeat
44 , repeatM
44 , repeatM
45 , replicate
45 , replicate
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6
@@ -31,7 +31,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
31
31
32 -- * From Values
32 -- * From Values
33 , fromPure
33 , fromPure
34− , yieldM
34+ , fromEffect
35
35
36 -- * From Containers
36 -- * From Containers
37 , fromList
37 , fromList
@@ -197,9 +197,9 @@ fromPure x = Stream (\_ s -> pure $ step undefined s) True
197 step _ False = Stop
197 step _ False = Stop
198
198
199-- | Create a singleton 'Stream' from a monadic action.
199-- | Create a singleton 'Stream' from a monadic action.
200−{-# INLINE_NORMAL yieldM #-}
200+{-# INLINE_NORMAL fromEffect #-}
201−yieldM :: Monad m => m a -> Stream m a
201+fromEffect :: Monad m => m a -> Stream m a
202−yieldM m = Stream step True
202+fromEffect m = Stream step True
203 where
203 where
204 {-# INLINE_LATE step #-}
204 {-# INLINE_LATE step #-}
205 step _ True = m >>= \x -> return $ Yield x False
205 step _ True = m >>= \x -> return $ Yield x False
@@ -373,7 +373,7 @@ foldrS f final (Stream step state) = go SPEC state
373 {-# INLINE_LATE go #-}
373 {-# INLINE_LATE go #-}
374 go !_ st = do
374 go !_ st = do
375 -- defState??
375 -- defState??
376− r <- yieldM $ step defState st
376+ r <- fromEffect $ step defState st
377 case r of
377 case r of
378 Yield x s -> f x (go SPEC s)
378 Yield x s -> f x (go SPEC s)
379 Skip s -> go SPEC s
379 Skip s -> go SPEC s
@@ -965,7 +965,7 @@ groupsOf2 n input (Fold2 fstep inject extract) (Stream step state) =
965
965
966instance MonadTrans Stream where
966instance MonadTrans Stream where
967 {-# INLINE lift #-}
967 {-# INLINE lift #-}
968− lift = yieldM
968+ lift = fromEffect
969
969
970instance (MonadThrow m) => MonadThrow (Stream m) where
970instance (MonadThrow m) => MonadThrow (Stream m) where
971 throwM = lift . throwM
971 throwM = lift . throwM
src/Streamly/Internal/Data/Stream/StreamK.hs+4−4
@@ -62,7 +62,7 @@ module Streamly.Internal.Data.Stream.StreamK
62
62
63 -- ** Conversions
63 -- ** Conversions
64 , fromPure
64 , fromPure
65− , yieldM
65+ , fromEffect
66 , fromFoldable
66 , fromFoldable
67 , fromList
67 , fromList
68 , fromStreamK
68 , fromStreamK
@@ -261,13 +261,13 @@ unfoldrA = undefined
261-- Special generation
261-- Special generation
262-------------------------------------------------------------------------------
262-------------------------------------------------------------------------------
263
263
264−-- | Same as yieldM
264+-- | Same as fromEffect
265--
265--
266-- @since 0.2.0
266-- @since 0.2.0
267−{-# DEPRECATED once "Please use yieldM instead." #-}
267+{-# DEPRECATED once "Please use fromEffect instead." #-}
268{-# INLINE once #-}
268{-# INLINE once #-}
269once :: (Monad m, IsStream t) => m a -> t m a
269once :: (Monad m, IsStream t) => m a -> t m a
270−once = yieldM
270+once = fromEffect
271
271
272-- |
272-- |
273-- @
273-- @
src/Streamly/Internal/Data/Stream/StreamK/Type.hs+8−8
@@ -54,7 +54,7 @@ module Streamly.Internal.Data.Stream.StreamK.Type
54 , (.:)
54 , (.:)
55 , consMStream
55 , consMStream
56 , consMBy
56 , consMBy
57− , yieldM
57+ , fromEffect
58 , fromPure
58 , fromPure
59
59
60 , nil
60 , nil
@@ -349,15 +349,15 @@ nilM m = mkStream $ \_ _ _ stp -> m >> stp
349fromPure :: IsStream t => a -> t m a
349fromPure :: IsStream t => a -> t m a
350fromPure a = mkStream $ \_ _ single _ -> single a
350fromPure a = mkStream $ \_ _ single _ -> single a
351
351
352−{-# INLINE_NORMAL yieldM #-}
352+{-# INLINE_NORMAL fromEffect #-}
353−yieldM :: (Monad m, IsStream t) => m a -> t m a
353+fromEffect :: (Monad m, IsStream t) => m a -> t m a
354−yieldM m = fromStream $ mkStream $ \_ _ single _ -> m >>= single
354+fromEffect m = fromStream $ mkStream $ \_ _ single _ -> m >>= single
355
355
356-- XXX specialize to IO?
356-- XXX specialize to IO?
357{-# INLINE consMBy #-}
357{-# INLINE consMBy #-}
358consMBy :: (IsStream t, MonadAsync m) => (t m a -> t m a -> t m a)
358consMBy :: (IsStream t, MonadAsync m) => (t m a -> t m a -> t m a)
359 -> m a -> t m a -> t m a
359 -> m a -> t m a -> t m a
360−consMBy f m r = (fromStream $ yieldM m) `f` r
360+consMBy f m r = (fromStream $ fromEffect m) `f` r
361
361
362------------------------------------------------------------------------------
362------------------------------------------------------------------------------
363-- Folding a stream
363-- Folding a stream
@@ -534,7 +534,7 @@ foldrSM = foldrSMWith foldStream
534
534
535-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
535-- {-# RULES "foldrSM/id" foldrSM consM nil = \x -> x #-}
536{-# RULES "foldrSM/nil" forall k z. foldrSM k z nil = z #-}
536{-# RULES "foldrSM/nil" forall k z. foldrSM k z nil = z #-}
537−{-# RULES "foldrSM/single" forall k z x. foldrSM k z (yieldM x) = k x z #-}
537+{-# RULES "foldrSM/single" forall k z x. foldrSM k z (fromEffect x) = k x z #-}
538-- {-# RULES "foldrSM/app" [1]
538-- {-# RULES "foldrSM/app" [1]
539-- forall ys. foldrSM consM ys = \xs -> xs `conjoin` ys #-}
539-- forall ys. foldrSM consM ys = \xs -> xs `conjoin` ys #-}
540
540
@@ -548,7 +548,7 @@ foldrSMShared = foldrSMWith foldStreamShared
548{-# RULES "foldrSMShared/nil"
548{-# RULES "foldrSMShared/nil"
549 forall k z. foldrSMShared k z nil = z #-}
549 forall k z. foldrSMShared k z nil = z #-}
550{-# RULES "foldrSMShared/single"
550{-# RULES "foldrSMShared/single"
551− forall k z x. foldrSMShared k z (yieldM x) = k x z #-}
551+ forall k z x. foldrSMShared k z (fromEffect x) = k x z #-}
552-- {-# RULES "foldrSM/app" [1]
552-- {-# RULES "foldrSM/app" [1]
553-- forall ys. foldrSM consM ys = \xs -> xs `conjoin` ys #-}
553-- forall ys. foldrSM consM ys = \xs -> xs `conjoin` ys #-}
554
554
@@ -933,7 +933,7 @@ instance Monad m => Functor (Stream m) where
933
933
934instance MonadTrans Stream where
934instance MonadTrans Stream where
935 {-# INLINE lift #-}
935 {-# INLINE lift #-}
936− lift = yieldM
936+ lift = fromEffect
937
937
938-------------------------------------------------------------------------------
938-------------------------------------------------------------------------------
939-- Nesting
939-- Nesting
src/Streamly/Internal/Network/Inet/TCP.hs+1−1
@@ -340,7 +340,7 @@ putChunks
340 -> SerialT m (Array Word8)
340 -> SerialT m (Array Word8)
341 -> m ()
341 -> m ()
342putChunks addr port xs =
342putChunks addr port xs =
343− S.drain $ withConnection addr port (\sk -> S.yieldM $ ISK.putChunks sk xs)
343+ S.drain $ withConnection addr port (\sk -> S.fromEffect $ ISK.putChunks sk xs)
344
344
345-- | Write a stream of arrays to the supplied IPv4 host address and port
345-- | Write a stream of arrays to the supplied IPv4 host address and port
346-- number.
346-- number.
src/Streamly/Prelude.hs+2−1
@@ -348,7 +348,7 @@ module Streamly.Prelude
348 -- ** From Values
348 -- ** From Values
349 -- | Generate a monadic stream from a seed value or values.
349 -- | Generate a monadic stream from a seed value or values.
350 , fromPure
350 , fromPure
351− , yieldM
351+ , fromEffect
352 , repeat
352 , repeat
353 , repeatM
353 , repeatM
354 , replicate
354 , replicate
@@ -921,6 +921,7 @@ module Streamly.Prelude
921 -- * Deprecated
921 -- * Deprecated
922 , once
922 , once
923 , yield
923 , yield
924+ , yieldM
924 , each
925 , each
925 , scanx
926 , scanx
926 , foldx
927 , foldx
src/Streamly/Tutorial.hs+13−13
@@ -192,7 +192,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
192-- represents a single IO action whereas the 'Serial' monad represents a series
192-- represents a single IO action whereas the 'Serial' monad represents a series
193-- of IO actions. The only change you need to make to go from 'IO' to 'Serial'
193-- of IO actions. The only change you need to make to go from 'IO' to 'Serial'
194-- is to use 'drain' to run the monad and to prefix the IO actions with
194-- is to use 'drain' to run the monad and to prefix the IO actions with
195−-- either 'yieldM' or 'liftIO'. If you use liftIO you can switch from 'Serial'
195+-- either 'fromEffect' or 'liftIO'. If you use liftIO you can switch from 'Serial'
196-- to IO monad by simply removing the 'drain' function; no other changes
196-- to IO monad by simply removing the 'drain' function; no other changes
197-- are needed unless you have used some stream specific composition or
197-- are needed unless you have used some stream specific composition or
198-- combinators.
198-- combinators.
@@ -364,7 +364,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
364-- @
364-- @
365--
365--
366-- To create a singleton stream from a pure value use 'fromPure' or 'pure' and to
366-- To create a singleton stream from a pure value use 'fromPure' or 'pure' and to
367−-- create a singleton stream from a monadic action use 'yieldM'. Note that in
367+-- create a singleton stream from a monadic action use 'fromEffect'. Note that in
368-- case of Zip applicative streams "pure" repeats the value to generate an
368-- case of Zip applicative streams "pure" repeats the value to generate an
369-- infinite stream.
369-- infinite stream.
370--
370--
@@ -373,7 +373,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
373-- [1]
373-- [1]
374-- > S.'toList' $ S.'fromPure' 1
374-- > S.'toList' $ S.'fromPure' 1
375-- [1]
375-- [1]
376−-- > S.'toList' $ S.'yieldM' 'getLine'
376+-- > S.'toList' $ S.'fromEffect' 'getLine'
377-- hello
377-- hello
378-- ["hello"]
378-- ["hello"]
379-- @
379-- @
@@ -529,7 +529,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
529-- seconds. After the delay it prints the number of seconds it slept.
529-- seconds. After the delay it prints the number of seconds it slept.
530--
530--
531-- @
531-- @
532−-- delay n = S.'yieldM' $ do
532+-- delay n = S.'fromEffect' $ do
533-- threadDelay (n * 1000000)
533-- threadDelay (n * 1000000)
534-- tid \<- myThreadId
534-- tid \<- myThreadId
535-- putStrLn (show tid ++ ": Delay " ++ show n)
535-- putStrLn (show tid ++ ": Delay " ++ show n)
@@ -760,7 +760,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
760--
760--
761-- @
761-- @
762-- main = S.'drain' . S.'fromAsync' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
762-- main = S.'drain' . S.'fromAsync' $ traced (sqrt 9) '<>' traced (sqrt 16) '<>' traced (sqrt 25)
763−-- where traced m = S.'yieldM' (myThreadId >>= print) >> return m
763+-- where traced m = S.'fromEffect' (myThreadId >>= print) >> return m
764-- @
764-- @
765-- @
765-- @
766-- ThreadId 40
766-- ThreadId 40
@@ -882,7 +882,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
882-- google = get "https://www.google.com/search?q=haskell"
882-- google = get "https://www.google.com/search?q=haskell"
883-- bing = get "https://www.bing.com/search?q=haskell"
883-- bing = get "https://www.bing.com/search?q=haskell"
884-- duckduckgo = get "https://www.duckduckgo.com/?q=haskell"
884-- duckduckgo = get "https://www.duckduckgo.com/?q=haskell"
885−-- get s = S.'yieldM' (httpNoBody (parseRequest_ s) >> putStrLn (show s))
885+-- get s = S.'fromEffect' (httpNoBody (parseRequest_ s) >> putStrLn (show s))
886-- @
886-- @
887--
887--
888-- The polymorphic version of the binary operation '<>' of the 'Parallel' type
888-- The polymorphic version of the binary operation '<>' of the 'Parallel' type
@@ -941,7 +941,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
941-- S.'drain' $ S.'concatFoldableWith' S.'async' (map delay [1..10])
941-- S.'drain' $ S.'concatFoldableWith' S.'async' (map delay [1..10])
942-- S.'drain' $ S.'concatMapFoldableWith' S.'async' delay [1..10]
942-- S.'drain' $ S.'concatMapFoldableWith' S.'async' delay [1..10]
943-- S.'drain' $ S.'concatForFoldableWith' S.'async' [1..10] delay
943-- S.'drain' $ S.'concatForFoldableWith' S.'async' [1..10] delay
944−-- where delay n = S.'yieldM' $ threadDelay (n * 1000000) >> print n
944+-- where delay n = S.'fromEffect' $ threadDelay (n * 1000000) >> print n
945-- @
945-- @
946
946
947-- $nesting
947-- $nesting
@@ -1011,7 +1011,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1011--
1011--
1012-- import Control.Monad (forever)
1012-- import Control.Monad (forever)
1013--
1013--
1014−-- main = S.'drain' $ forever $ S.'yieldM' getLine >>= S.'yieldM' . putStrLn
1014+-- main = S.'drain' $ forever $ S.'fromEffect' getLine >>= S.'fromEffect' . putStrLn
1015-- @
1015-- @
1016--
1016--
1017-- When multiple streams are composed using this style they nest in a DFS
1017-- When multiple streams are composed using this style they nest in a DFS
@@ -1025,7 +1025,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1025-- main = S.'drain' $ do
1025-- main = S.'drain' $ do
1026-- x <- S.'fromFoldable' [1,2]
1026-- x <- S.'fromFoldable' [1,2]
1027-- y <- S.'fromFoldable' [3,4]
1027-- y <- S.'fromFoldable' [3,4]
1028−-- S.'yieldM' $ putStrLn $ show (x, y)
1028+-- S.'fromEffect' $ putStrLn $ show (x, y)
1029-- @
1029-- @
1030-- @
1030-- @
1031-- (1,3)
1031-- (1,3)
@@ -1119,7 +1119,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1119-- main = S.'drain' . S.'fromAsync' $ do
1119-- main = S.'drain' . S.'fromAsync' $ do
1120-- x <- S.'fromFoldable' [1,2]
1120-- x <- S.'fromFoldable' [1,2]
1121-- y <- S.'fromFoldable' [3,4]
1121-- y <- S.'fromFoldable' [3,4]
1122−-- S.'yieldM' $ putStrLn $ show (x, y)
1122+-- S.'fromEffect' $ putStrLn $ show (x, y)
1123-- @
1123-- @
1124-- @
1124-- @
1125-- (1,3)
1125-- (1,3)
@@ -1143,7 +1143,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1143-- main = S.'drain' . S.'fromWSerial' $ do
1143-- main = S.'drain' . S.'fromWSerial' $ do
1144-- x <- S.'fromFoldable' [1,2]
1144-- x <- S.'fromFoldable' [1,2]
1145-- y <- S.'fromFoldable' [3,4]
1145-- y <- S.'fromFoldable' [3,4]
1146−-- S.yieldM $ putStrLn $ show (x, y)
1146+-- S.fromEffect $ putStrLn $ show (x, y)
1147-- @
1147-- @
1148-- @
1148-- @
1149-- (1,3)
1149-- (1,3)
@@ -1170,7 +1170,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1170-- main = S.'drain' . S.'fromWAsync' $ do
1170-- main = S.'drain' . S.'fromWAsync' $ do
1171-- x <- S.'fromFoldable' [1,2]
1171-- x <- S.'fromFoldable' [1,2]
1172-- y <- S.'fromFoldable' [3,4]
1172-- y <- S.'fromFoldable' [3,4]
1173−-- S.'yieldM' $ putStrLn $ show (x, y)
1173+-- S.'fromEffect' $ putStrLn $ show (x, y)
1174-- @
1174-- @
1175-- @
1175-- @
1176-- (1,3)
1176-- (1,3)
@@ -1217,7 +1217,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1217-- sz <- sizes
1217-- sz <- sizes
1218-- cl <- colors
1218-- cl <- colors
1219-- sh <- shapes
1219-- sh <- shapes
1220−-- S.'yieldM' $ putStrLn $ show (sz, cl, sh)
1220+-- S.'fromEffect' $ putStrLn $ show (sz, cl, sh)
1221--
1221--
1222-- where
1222-- where
1223--
1223--
test/Streamly/Test/FileSystem/Event.hs+3−3
@@ -154,9 +154,9 @@ checkEvents rootPath m matchList = do
154checker :: S.IsStream t =>
154checker :: S.IsStream t =>
155 FilePath -> MVar () -> [String] -> t IO String
155 FilePath -> MVar () -> [String] -> t IO String
156checker rootPath synch matchList =
156checker rootPath synch matchList =
157− S.yieldM (checkEvents rootPath synch matchList)
157+ S.fromEffect (checkEvents rootPath synch matchList)
158 `S.parallelFst`
158 `S.parallelFst`
159− S.yieldM timeout
159+ S.fromEffect timeout
160
160
161-------------------------------------------------------------------------------
161-------------------------------------------------------------------------------
162-- Test Drivers
162-- Test Drivers
@@ -178,7 +178,7 @@ driver (desc, pre, ops, events) = it desc $ runTest `shouldReturn` "PASS"
178 withSystemTempDirectory fseventDir $ \fp -> do
178 withSystemTempDirectory fseventDir $ \fp -> do
179 pre fp
179 pre fp
180 let eventStream = checker fp sync events
180 let eventStream = checker fp sync events
181− fsOps = S.yieldM $ runFSOps fp sync
181+ fsOps = S.fromEffect $ runFSOps fp sync
182 fmap fromJust $ S.head $ eventStream `S.parallelFst` fsOps
182 fmap fromJust $ S.head $ eventStream `S.parallelFst` fsOps
183
183
184 runFSOps fp sync = do
184 runFSOps fp sync = do
test/Streamly/Test/Prelude.hs+21−21
@@ -77,21 +77,21 @@ mixedOps =
77
77
78 composeMixed :: SerialT IO Int
78 composeMixed :: SerialT IO Int
79 composeMixed = do
79 composeMixed = do
80− S.yieldM $ return ()
80+ S.fromEffect $ return ()
81− S.yieldM $ putStr ""
81+ S.fromEffect $ putStr ""
82 let x = 1
82 let x = 1
83 let y = 2
83 let y = 2
84 z <- do
84 z <- do
85 x1 <- S.fromWAsync $ return 1 <> return 2
85 x1 <- S.fromWAsync $ return 1 <> return 2
86− S.yieldM $ return ()
86+ S.fromEffect $ return ()
87− S.yieldM $ putStr ""
87+ S.fromEffect $ putStr ""
88 y1 <- S.fromAsync $ return 1 <> return 2
88 y1 <- S.fromAsync $ return 1 <> return 2
89 z1 <- do
89 z1 <- do
90 x11 <- return 1 <> return 2
90 x11 <- return 1 <> return 2
91 y11 <- S.fromAsync $ return 1 <> return 2
91 y11 <- S.fromAsync $ return 1 <> return 2
92 z11 <- S.fromWSerial $ return 1 <> return 2
92 z11 <- S.fromWSerial $ return 1 <> return 2
93− S.yieldM $ return ()
93+ S.fromEffect $ return ()
94− S.yieldM $ putStr ""
94+ S.fromEffect $ putStr ""
95 return (x11 + y11 + z11)
95 return (x11 + y11 + z11)
96 return (x1 + y1 + z1)
96 return (x1 + y1 + z1)
97 return (x + y + z)
97 return (x + y + z)
@@ -107,21 +107,21 @@ mixedOpsAheadly =
107
107
108 composeMixed :: SerialT IO Int
108 composeMixed :: SerialT IO Int
109 composeMixed = do
109 composeMixed = do
110− S.yieldM $ return ()
110+ S.fromEffect $ return ()
111− S.yieldM $ putStr ""
111+ S.fromEffect $ putStr ""
112 let x = 1
112 let x = 1
113 let y = 2
113 let y = 2
114 z <- do
114 z <- do
115 x1 <- S.fromWAsync $ return 1 <> return 2
115 x1 <- S.fromWAsync $ return 1 <> return 2
116− S.yieldM $ return ()
116+ S.fromEffect $ return ()
117− S.yieldM $ putStr ""
117+ S.fromEffect $ putStr ""
118 y1 <- S.fromAhead $ return 1 <> return 2
118 y1 <- S.fromAhead $ return 1 <> return 2
119 z1 <- do
119 z1 <- do
120 x11 <- return 1 <> return 2
120 x11 <- return 1 <> return 2
121 y11 <- S.fromAhead $ return 1 <> return 2
121 y11 <- S.fromAhead $ return 1 <> return 2
122 z11 <- S.fromParallel $ return 1 <> return 2
122 z11 <- S.fromParallel $ return 1 <> return 2
123− S.yieldM $ return ()
123+ S.fromEffect $ return ()
124− S.yieldM $ putStr ""
124+ S.fromEffect $ putStr ""
125 return (x11 + y11 + z11)
125 return (x11 + y11 + z11)
126 return (x1 + y1 + z1)
126 return (x1 + y1 + z1)
127 return (x + y + z)
127 return (x + y + z)
@@ -129,20 +129,20 @@ mixedOpsAheadly =
129-- XXX Merge both the loops.
129-- XXX Merge both the loops.
130nestedLoops :: IO ()
130nestedLoops :: IO ()
131nestedLoops = S.drain $ do
131nestedLoops = S.drain $ do
132− S.yieldM $ hSetBuffering stdout LineBuffering
132+ S.fromEffect $ hSetBuffering stdout LineBuffering
133 x <- loop "A " 2
133 x <- loop "A " 2
134 y <- loop "B " 2
134 y <- loop "B " 2
135− S.yieldM $ myThreadId >>= putStr . show
135+ S.fromEffect $ myThreadId >>= putStr . show
136 >> putStr " "
136 >> putStr " "
137 >> print (x, y)
137 >> print (x, y)
138
138
139 where
139 where
140
140
141 -- we can just use
141 -- we can just use
142− -- fromParallel $ mconcat $ replicate n $ yieldM (...)
142+ -- fromParallel $ mconcat $ replicate n $ fromEffect (...)
143 loop :: String -> Int -> SerialT IO String
143 loop :: String -> Int -> SerialT IO String
144 loop name n = do
144 loop name n = do
145− rnd <- S.yieldM (randomIO :: IO Int)
145+ rnd <- S.fromEffect (randomIO :: IO Int)
146 let result = name <> show rnd
146 let result = name <> show rnd
147 repeatIt = if n > 1 then loop name (n - 1) else S.nil
147 repeatIt = if n > 1 then loop name (n - 1) else S.nil
148 in return result `S.wAsync` repeatIt
148 in return result `S.wAsync` repeatIt
@@ -152,19 +152,19 @@ parallelLoops = do
152 hSetBuffering stdout LineBuffering
152 hSetBuffering stdout LineBuffering
153 S.drain $ do
153 S.drain $ do
154 x <- S.take 10 $ loop "A" `S.parallel` loop "B"
154 x <- S.take 10 $ loop "A" `S.parallel` loop "B"
155− S.yieldM $ myThreadId >>= putStr . show
155+ S.fromEffect $ myThreadId >>= putStr . show
156 >> putStr " got "
156 >> putStr " got "
157 >> print x
157 >> print x
158
158
159 where
159 where
160
160
161 -- we can just use
161 -- we can just use
162− -- fromParallel $ cycle1 $ yieldM (...)
162+ -- fromParallel $ cycle1 $ fromEffect (...)
163 loop :: String -> SerialT IO (String, Int)
163 loop :: String -> SerialT IO (String, Int)
164 loop name = do
164 loop name = do
165− S.yieldM $ threadDelay 1000000
165+ S.fromEffect $ threadDelay 1000000
166− rnd <- S.yieldM (randomIO :: IO Int)
166+ rnd <- S.fromEffect (randomIO :: IO Int)
167− S.yieldM $ myThreadId >>= putStr . show
167+ S.fromEffect $ myThreadId >>= putStr . show
168 >> putStr " yielding "
168 >> putStr " yielding "
169 >> print rnd
169 >> print rnd
170 return (name, rnd) `S.parallel` loop name
170 return (name, rnd) `S.parallel` loop name
test/Streamly/Test/Prelude/Concurrent.hs+5−5
@@ -129,10 +129,10 @@ concurrentUnfoldrM eq op n =
129 -- results may not be yielded in order, in case of
129 -- results may not be yielded in order, in case of
130 -- Async/WAsync/Parallel. So we use an increasing count
130 -- Async/WAsync/Parallel. So we use an increasing count
131 -- instead.
131 -- instead.
132− i <- S.yieldM $ readIORef cnt
132+ i <- S.fromEffect $ readIORef cnt
133− S.yieldM $ modifyIORef cnt (+1)
133+ S.fromEffect $ modifyIORef cnt (+1)
134 let msg = show i <> "/" <> show n
134 let msg = show i <> "/" <> show n
135− S.yieldM $
135+ S.fromEffect $
136 when (even i) $ do
136 when (even i) $ do
137 dbgMVar ("first take concurrentUnfoldrM " <> msg)
137 dbgMVar ("first take concurrentUnfoldrM " <> msg)
138 (takeMVar mv)
138 (takeMVar mv)
@@ -484,12 +484,12 @@ main = hspec
484
484
485 it "asyncly crosses thread limit (2000 threads)" $
485 it "asyncly crosses thread limit (2000 threads)" $
486 S.drain (fromAsync $ fold $
486 S.drain (fromAsync $ fold $
487− replicate 2000 $ S.yieldM $ threadDelay 1000000)
487+ replicate 2000 $ S.fromEffect $ threadDelay 1000000)
488 `shouldReturn` ()
488 `shouldReturn` ()
489
489
490 it "aheadly crosses thread limit (4000 threads)" $
490 it "aheadly crosses thread limit (4000 threads)" $
491 S.drain (fromAhead $ fold $
491 S.drain (fromAhead $ fold $
492− replicate 4000 $ S.yieldM $ threadDelay 1000000)
492+ replicate 4000 $ S.fromEffect $ threadDelay 1000000)
493 `shouldReturn` ()
493 `shouldReturn` ()
494
494
495#ifdef DEVBUILD
495#ifdef DEVBUILD
test/Streamly/Test/Prelude/Serial.hs+3−3
@@ -473,7 +473,7 @@ testFromCallback = do
473 setCallback ref cb = do
473 setCallback ref cb = do
474 writeIORef ref (Just cb)
474 writeIORef ref (Just cb)
475
475
476− runCallback ref = S.yieldM $ do
476+ runCallback ref = S.fromEffect $ do
477 cb <-
477 cb <-
478 S.repeatM (readIORef ref)
478 S.repeatM (readIORef ref)
479 & IS.delayPost 0.1
479 & IS.delayPost 0.1
@@ -526,7 +526,7 @@ main = hspec
526 it "simple serially" $
526 it "simple serially" $
527 (S.drain . fromSerial) (return (0 :: Int)) `shouldReturn` ()
527 (S.drain . fromSerial) (return (0 :: Int)) `shouldReturn` ()
528 it "simple serially with IO" $
528 it "simple serially with IO" $
529− (S.drain . fromSerial) (S.yieldM $ putStrLn "hello") `shouldReturn` ()
529+ (S.drain . fromSerial) (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
530
530
531 describe "Empty" $
531 describe "Empty" $
532 it "Monoid - mempty" $
532 it "Monoid - mempty" $
@@ -559,7 +559,7 @@ main = hspec
559 serialOps $ prop "serially fromListM" . constructWithFromListM id
559 serialOps $ prop "serially fromListM" . constructWithFromListM id
560 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
560 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
561 serialOps $ prop "serially fromPure" . constructWithYield id
561 serialOps $ prop "serially fromPure" . constructWithYield id
562− serialOps $ prop "serially yieldM" . constructWithYieldM id
562+ serialOps $ prop "serially fromEffect" . constructWithFromEffect id
563 serialOps $ prop "serially cons" . constructWithCons S.cons
563 serialOps $ prop "serially cons" . constructWithCons S.cons
564 serialOps $ prop "serially consM" . constructWithConsM S.consM id
564 serialOps $ prop "serially consM" . constructWithConsM S.consM id
565 serialOps $ prop "serially (.:)" . constructWithCons (S..:)
565 serialOps $ prop "serially (.:)" . constructWithCons (S..:)
test/Streamly/Test/Prelude/WAsync.hs+1−1
@@ -122,7 +122,7 @@ main = hspec
122
122
123#ifdef DEVBUILD
123#ifdef DEVBUILD
124 let timed :: (IsStream t, Monad (t IO)) => Int -> t IO Int
124 let timed :: (IsStream t, Monad (t IO)) => Int -> t IO Int
125− timed x = S.yieldM (threadDelay (x * 100000)) >> return x
125+ timed x = S.fromEffect (threadDelay (x * 100000)) >> return x
126
126
127 -- These are not run fromParallel because the timing gets affected
127 -- These are not run fromParallel because the timing gets affected
128 -- unpredictably when other tests are running on the same machine.
128 -- unpredictably when other tests are running on the same machine.
test/lib/Streamly/Test/Prelude/Common.hs+8−8
@@ -30,7 +30,7 @@ module Streamly.Test.Prelude.Common
30 , constructWithCons
30 , constructWithCons
31 , constructWithConsM
31 , constructWithConsM
32 , constructWithYield
32 , constructWithYield
33− , constructWithYieldM
33+ , constructWithFromEffect
34 , simpleOps
34 , simpleOps
35 -- * Applicative operations
35 -- * Applicative operations
36 , applicativeOps
36 , applicativeOps
@@ -415,7 +415,7 @@ constructWithYield listT op len =
415 let list = replicate (fromIntegral len) 0
415 let list = replicate (fromIntegral len) 0
416 listEquals (==) (listT strm) list
416 listEquals (==) (listT strm) list
417
417
418−constructWithYieldM ::
418+constructWithFromEffect ::
419 (IsStream t
419 (IsStream t
420#if __GLASGOW_HASKELL__ < 806
420#if __GLASGOW_HASKELL__ < 806
421 , Monoid (t IO Int)
421 , Monoid (t IO Int)
@@ -425,13 +425,13 @@ constructWithYieldM ::
425 -> (t IO Int -> SerialT IO Int)
425 -> (t IO Int -> SerialT IO Int)
426 -> Word8
426 -> Word8
427 -> Property
427 -> Property
428−constructWithYieldM listT op len =
428+constructWithFromEffect listT op len =
429 withMaxSuccess maxTestCount $
429 withMaxSuccess maxTestCount $
430 monadicIO $ do
430 monadicIO $ do
431 strm <-
431 strm <-
432 run
432 run
433 $ S.toList . op . S.take (fromIntegral len)
433 $ S.toList . op . S.take (fromIntegral len)
434− $ foldMap S.yieldM (repeat (return 0))
434+ $ foldMap S.fromEffect (repeat (return 0))
435 let list = replicate (fromIntegral len) 0
435 let list = replicate (fromIntegral len) 0
436 listEquals (==) (listT strm) list
436 listEquals (==) (listT strm) list
437
437
@@ -447,7 +447,7 @@ simpleProps constr op a = monadicIO $ do
447simpleOps :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
447simpleOps :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
448simpleOps op = do
448simpleOps op = do
449 prop "fromPure a = a" $ simpleProps S.fromPure op
449 prop "fromPure a = a" $ simpleProps S.fromPure op
450− prop "yieldM a = a" $ simpleProps (S.yieldM . return) op
450+ prop "fromEffect a = a" $ simpleProps (S.fromEffect . return) op
451
451
452-------------------------------------------------------------------------------
452-------------------------------------------------------------------------------
453-- Applicative operations
453-- Applicative operations
@@ -786,12 +786,12 @@ loops t tsrt hsrt = do
786 where
786 where
787 loopHead x = do
787 loopHead x = do
788 -- this print line is important for the test (causes a bind)
788 -- this print line is important for the test (causes a bind)
789− S.yieldM $ putStrLn "LoopHead..."
789+ S.fromEffect $ putStrLn "LoopHead..."
790 t $ (if x < 3 then loopHead (x + 1) else nil) <> return x
790 t $ (if x < 3 then loopHead (x + 1) else nil) <> return x
791
791
792 loopTail x = do
792 loopTail x = do
793 -- this print line is important for the test (causes a bind)
793 -- this print line is important for the test (causes a bind)
794− S.yieldM $ putStrLn "LoopTail..."
794+ S.fromEffect $ putStrLn "LoopTail..."
795 t $ return x <> (if x < 3 then loopTail (x + 1) else nil)
795 t $ return x <> (if x < 3 then loopTail (x + 1) else nil)
796
796
797---------------------------------------------------------------------------
797---------------------------------------------------------------------------
@@ -1385,7 +1385,7 @@ parallelCheck t f = do
1385 (S.toList . t) (event 4 `f` (event 3 `f` (event 2 `f` event 1)))
1385 (S.toList . t) (event 4 `f` (event 3 `f` (event 2 `f` event 1)))
1386 `shouldReturn` [1..4]
1386 `shouldReturn` [1..4]
1387
1387
1388− where event n = S.yieldM (threadDelay (n * 200000)) >> return n
1388+ where event n = S.fromEffect (threadDelay (n * 200000)) >> return n
1389
1389
1390-------------------------------------------------------------------------------
1390-------------------------------------------------------------------------------
1391-- Exception ops
1391-- Exception ops