on master help sign in
Rename Streamly.Prelude.yield to fromPure.
4dfc6bfPranay Sashank
Changelog.md+3−1
@@ -90,7 +90,9 @@
90 * `foldMapWith` to `concatMapFoldableWith`
90 * `foldMapWith` to `concatMapFoldableWith`
91 * `forEachWith` to `concatForFoldableWith`
91 * `forEachWith` to `concatForFoldableWith`
92 * `serially` to `fromSerial` and so on
92 * `serially` to `fromSerial` and so on
93+* In `Streamly.Prelude` the following functions have been renamed:
93−* In `Streamly.Prelude`, `concatUnfold` is renamed to `unfoldMany`
94+ * `concatUnfold` to `unfoldMany`
95+ * `yield` to `fromPure`
94* The following encoding/decoding routines have been renamed:
96* The following encoding/decoding routines have been renamed:
95 * `encodeUtf8Lax` to `encodeUtf8`
97 * `encodeUtf8Lax` to `encodeUtf8`
96 * `encodeLatin1Lax` to `encodeLatin1`
98 * `encodeLatin1Lax` to `encodeLatin1`
benchmark/Streamly/Benchmark/Data/Parser.hs+1−1
@@ -89,7 +89,7 @@ drainWhile value = IP.parse (PR.drainWhile (<= value))
89{-# INLINE sliceBeginWith #-}
89{-# INLINE sliceBeginWith #-}
90sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
90sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
91sliceBeginWith value stream = do
91sliceBeginWith value stream = do
92− stream1 <- return . fromMaybe (S.yield (value + 1)) =<< S.tail stream
92+ stream1 <- return . fromMaybe (S.fromPure (value + 1)) =<< S.tail stream
93 let stream2 = value `S.cons` stream1
93 let stream2 = value `S.cons` stream1
94 IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2
94 IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2
95
95
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+1−1
@@ -71,7 +71,7 @@ drainWhile p = PR.takeWhile p FL.drain
71{-# INLINE sliceBeginWith #-}
71{-# INLINE sliceBeginWith #-}
72sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
72sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
73sliceBeginWith value stream = do
73sliceBeginWith value stream = do
74− stream1 <- return . fromMaybe (S.yield (value + 1)) =<< S.tail stream
74+ stream1 <- return . fromMaybe (S.fromPure (value + 1)) =<< S.tail stream
75 let stream2 = value `S.cons` stream1
75 let stream2 = value `S.cons` stream1
76 IP.parseD (PR.sliceBeginWith (== value) FL.drain) stream2
76 IP.parseD (PR.sliceBeginWith (== value) FL.drain) stream2
77
77
benchmark/Streamly/Benchmark/Data/Stream/StreamDK.hs+1−1
@@ -104,7 +104,7 @@ sourceFromFoldableM n = S.fromFoldableM (Prelude.fmap return [n..n+value])
104{-
104{-
105{-# INLINE sourceFoldMapWith #-}
105{-# INLINE sourceFoldMapWith #-}
106sourceFoldMapWith :: Int -> Stream m Int
106sourceFoldMapWith :: Int -> Stream m Int
107−sourceFoldMapWith n = SP.foldMapWith S.serial S.yield [n..n+value]
107+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
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+1−1
@@ -154,7 +154,7 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
154
154
155{-# INLINE concatMapFoldableSerial #-}
155{-# INLINE concatMapFoldableSerial #-}
156concatMapFoldableSerial :: Int -> Int -> Stream m Int
156concatMapFoldableSerial :: Int -> Int -> Stream m Int
157−concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.yield [n..n+streamLen]
157+concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.fromPure [n..n+streamLen]
158
158
159{-# INLINE concatMapFoldableSerialM #-}
159{-# INLINE concatMapFoldableSerialM #-}
160concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
160concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
benchmark/lib/Streamly/Benchmark/Prelude.hs+4−4
@@ -294,13 +294,13 @@ transformZipMapM t n =
294{-# INLINE sourceFoldMapWith #-}
294{-# INLINE sourceFoldMapWith #-}
295sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
295sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
296 => Int -> Int -> t m Int
296 => Int -> Int -> t m Int
297−sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.yield [n..n+value]
297+sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.fromPure [n..n+value]
298
298
299{-# INLINE concatForFoldableWith #-}
299{-# INLINE concatForFoldableWith #-}
300concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int))
300concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int))
301 => Int -> Int -> t m Int
301 => Int -> Int -> t m Int
302concatForFoldableWith value n =
302concatForFoldableWith value n =
303− S.concatForFoldableWith (<>) [n..n+value] S.yield
303+ S.concatForFoldableWith (<>) [n..n+value] S.fromPure
304
304
305{-# INLINE concatFoldableWith #-}
305{-# INLINE concatFoldableWith #-}
306concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
306concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
@@ -308,7 +308,7 @@ concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
308concatFoldableWith value n =
308concatFoldableWith value n =
309 let step x =
309 let step x =
310 if x <= n + value
310 if x <= n + value
311− then Just (S.yield x, x + 1)
311+ then Just (S.fromPure x, x + 1)
312 else Nothing
312 else Nothing
313 list = List.unfoldr step n
313 list = List.unfoldr step n
314 in S.concatFoldableWith (<>) list
314 in S.concatFoldableWith (<>) list
@@ -316,7 +316,7 @@ concatFoldableWith value n =
316{-# INLINE sourceFoldMapWithStream #-}
316{-# INLINE sourceFoldMapWithStream #-}
317sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
317sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
318 => Int -> Int -> t m Int
318 => Int -> Int -> t m Int
319−sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.yield
319+sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.fromPure
320 $ (S.enumerateFromTo n (n + value) :: S.SerialT Identity Int)
320 $ (S.enumerateFromTo n (n + value) :: S.SerialT Identity Int)
321
321
322{-# INLINE sourceFoldMapWithM #-}
322{-# INLINE sourceFoldMapWithM #-}
design/cps-vs-direct.rst+4−4
@@ -21,8 +21,8 @@ Generating
21 nil = Stream (const (return Stop)) ()
21 nil = Stream (const (return Stop)) ()
22
22
23 -- | A single value
23 -- | A single value
24− yield :: Applicative m => a -> Stream m a
24+ fromPure :: Applicative m => a -> Stream m a
25− yield x = Stream step True
25+ fromPure x = Stream step True
26
26
27 where
27 where
28
28
@@ -204,8 +204,8 @@ Generating
204 nil :: Stream m a
204 nil :: Stream m a
205 nil = Stream $ \_ stp -> stp
205 nil = Stream $ \_ stp -> stp
206
206
207− yield :: a -> Stream m a
207+ fromPure :: a -> Stream m a
208− yield a = Stream $ \yield _ -> yield a nil
208+ fromPure a = Stream $ \yield _ -> yield a nil
209
209
210 cons :: a -> Stream m a -> Stream m a
210 cons :: a -> Stream m a -> Stream m a
211 cons a r = Stream $ \yld _ -> yld a r
211 cons a r = Stream $ \yld _ -> yld a r
src/Streamly/Internal/Data/Sink.hs+1−1
@@ -190,7 +190,7 @@ demux kv = Sink step
190-- @
190-- @
191-- @
191-- @
192-- > let pr x = Sink.drainM (putStrLn . ((x ++ " ") ++) . show)
192-- > let pr x = Sink.drainM (putStrLn . ((x ++ " ") ++) . show)
193−-- in Sink.sink (Sink.unzip return (pr \"L") (pr \"R")) (S.yield (1,2))
193+-- in Sink.sink (Sink.unzip return (pr \"L") (pr \"R")) (S.fromPure (1,2))
194-- L 1
194-- L 1
195-- R 2
195-- R 2
196-- @
196-- @
src/Streamly/Internal/Data/Stream/Ahead.hs+1−1
@@ -786,7 +786,7 @@ apAhead (AheadT m1) (AheadT m2) =
786
786
787instance (Monad m, MonadAsync m) => Applicative (AheadT m) where
787instance (Monad m, MonadAsync m) => Applicative (AheadT m) where
788 {-# INLINE pure #-}
788 {-# INLINE pure #-}
789− pure = AheadT . K.yield
789+ pure = AheadT . K.fromPure
790 {-# INLINE (<*>) #-}
790 {-# INLINE (<*>) #-}
791 (<*>) = apAhead
791 (<*>) = apAhead
792
792
src/Streamly/Internal/Data/Stream/Async.hs+2−2
@@ -844,7 +844,7 @@ apAsync (AsyncT m1) (AsyncT m2) =
844
844
845instance (Monad m, MonadAsync m) => Applicative (AsyncT m) where
845instance (Monad m, MonadAsync m) => Applicative (AsyncT m) where
846 {-# INLINE pure #-}
846 {-# INLINE pure #-}
847− pure = AsyncT . K.yield
847+ pure = AsyncT . K.fromPure
848 {-# INLINE (<*>) #-}
848 {-# INLINE (<*>) #-}
849 (<*>) = apAsync
849 (<*>) = apAsync
850
850
@@ -1143,7 +1143,7 @@ apWAsync (WAsyncT m1) (WAsyncT m2) =
1143-- GHC: if we specify arguments in the definition of (<*>) we see a significant
1143-- GHC: if we specify arguments in the definition of (<*>) we see a significant
1144-- performance degradation (~2x).
1144-- performance degradation (~2x).
1145instance (Monad m, MonadAsync m) => Applicative (WAsyncT m) where
1145instance (Monad m, MonadAsync m) => Applicative (WAsyncT m) where
1146− pure = WAsyncT . K.yield
1146+ pure = WAsyncT . K.fromPure
1147 (<*>) = apWAsync
1147 (<*>) = apWAsync
1148
1148
1149------------------------------------------------------------------------------
1149------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+24−12
@@ -14,7 +14,7 @@
14module Streamly.Internal.Data.Stream.IsStream.Common
14module Streamly.Internal.Data.Stream.IsStream.Common
15 (
15 (
16 -- * Generation
16 -- * Generation
17− yield
17+ fromPure
18 , yieldM
18 , yieldM
19 , repeatM
19 , repeatM
20 , timesWith
20 , timesWith
@@ -44,6 +44,9 @@ module Streamly.Internal.Data.Stream.IsStream.Common
44 , concatMapM
44 , concatMapM
45 , concatMap
45 , concatMap
46 , splitOnSeq
46 , splitOnSeq
47+
48+ -- * Deprecated
49+ , yield
47 )
50 )
48where
51where
49
52
@@ -92,7 +95,7 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
92--
95--
93-- |
96-- |
94-- @
97-- @
95−-- yield a = a \`cons` nil
98+-- fromPure a = a \`cons` nil
96-- @
99-- @
97--
100--
98-- Create a singleton stream from a pure value.
101-- Create a singleton stream from a pure value.
@@ -100,19 +103,20 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
100-- The following holds in monadic streams, but not in Zip streams:
103-- The following holds in monadic streams, but not in Zip streams:
101--
104--
102-- @
105-- @
103−-- yield = pure
106+-- fromPure = pure
104−-- yield = yieldM . pure
107+-- fromPure = yieldM . pure
105-- @
108-- @
106--
109--
107−-- In Zip applicative streams 'yield' is not the same as 'pure' because in that
110+-- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
108−-- case 'pure' is equivalent to 'repeat' instead. 'yield' and 'pure' are
111+-- case 'pure' is equivalent to 'repeat' instead. 'fromPure' and 'pure' are
109−-- equally efficient, in other cases 'yield' may be slightly more efficient
112+-- equally efficient, in other cases 'fromPure' may be slightly more efficient
110-- than the other equivalent definitions.
113-- than the other equivalent definitions.
111--
114--
112−-- @since 0.4.0
115+-- /Since: 0.8.0 (Renamed yield to fromPure)/
116+--
113−{-# INLINE yield #-}
117+{-# INLINE fromPure #-}
114−yield :: IsStream t => a -> t m a
118+fromPure :: IsStream t => a -> t m a
115−yield = K.yield
119+fromPure = K.fromPure
116
120
117-- |
121-- |
118-- @
122-- @
@@ -484,7 +488,7 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
484--
488--
485{-# INLINE concatM #-}
489{-# INLINE concatM #-}
486concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
490concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
487−concatM generator = concatMapM (\() -> generator) (yield ())
491+concatM generator = concatMapM (\() -> generator) (fromPure ())
488
492
489------------------------------------------------------------------------------
493------------------------------------------------------------------------------
490-- Split stream and fold
494-- Split stream and fold
@@ -545,3 +549,11 @@ splitOnSeq
545 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
549 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
546 => Array a -> Fold m a b -> t m a -> t m b
550 => Array a -> Fold m a b -> t m a -> t m b
547splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m)
551splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m)
552+
553+-- | Same as 'yield'
554+--
555+-- @since 0.4.0
556+{-# DEPRECATED yield "Please use fromPure instead." #-}
557+{-# INLINE yield #-}
558+yield :: IsStream t => a -> t m a
559+yield = fromPure
src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+6−6
@@ -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, yield, yieldM)
164+ (concatM, concatMapM, concatMap, smapM, fromPure, yieldM)
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
@@ -685,7 +685,7 @@ concatMapEitherWith = undefined
685--
685--
686-- For example, you can sort a stream using merge sort like this:
686-- For example, you can sort a stream using merge sort like this:
687--
687--
688−-- >>> Stream.toList $ Stream.concatPairsWith (Stream.mergeBy compare) Stream.yield $ Stream.fromList [5,1,7,9,2]
688+-- >>> Stream.toList $ Stream.concatPairsWith (Stream.mergeBy compare) Stream.fromPure $ Stream.fromList [5,1,7,9,2]
689-- [1,2,5,7,9]
689-- [1,2,5,7,9]
690--
690--
691-- /Caution: the stream of streams must be finite/
691-- /Caution: the stream of streams must be finite/
@@ -723,7 +723,7 @@ concatPairsWith = K.concatPairsWith
723-- @
723-- @
724-- Stream.iterateMapWith Stream.serial
724-- Stream.iterateMapWith Stream.serial
725-- (either Dir.toEither (const nil))
725-- (either Dir.toEither (const nil))
726−-- (yield (Left "tmp"))
726+-- (fromPure (Left "tmp"))
727-- @
727-- @
728--
728--
729-- /Pre-release/
729-- /Pre-release/
@@ -737,7 +737,7 @@ iterateMapWith
737 -> t m a
737 -> t m a
738iterateMapWith combine f = concatMapWith combine go
738iterateMapWith combine f = concatMapWith combine go
739 where
739 where
740− go x = yield x `combine` concatMapWith combine go (f x)
740+ go x = fromPure x `combine` concatMapWith combine go (f x)
741
741
742{-
742{-
743{-# INLINE iterateUnfold #-}
743{-# INLINE iterateUnfold #-}
@@ -778,7 +778,7 @@ iterateSmapMWith combine f initial stream =
778
778
779 where
779 where
780
780
781− go b a = yield a `combine` feedback b a
781+ go b a = fromPure a `combine` feedback b a
782
782
783 feedback b a =
783 feedback b a =
784 concatMap
784 concatMap
@@ -799,7 +799,7 @@ iterateSmapMWith combine f initial stream =
799-- To traverse a directory tree:
799-- To traverse a directory tree:
800--
800--
801-- @
801-- @
802−-- iterateMapLeftsWith serial Dir.toEither (yield (Left "tmp"))
802+-- iterateMapLeftsWith serial Dir.toEither (fromPure (Left "tmp"))
803-- @
803-- @
804--
804--
805-- /Pre-release/
805-- /Pre-release/
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−2
@@ -35,7 +35,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
35 , unfoldrM
35 , unfoldrM
36
36
37 -- * From Values
37 -- * From Values
38− , yield
38+ , fromPure
39 , yieldM
39 , yieldM
40 , repeat
40 , repeat
41 , repeatM
41 , repeatM
@@ -79,6 +79,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
79
79
80 -- * Deprecated
80 -- * Deprecated
81 , K.once
81 , K.once
82+ , yield
82 , each
83 , each
83 , fromHandle
84 , fromHandle
84 , currentTime
85 , currentTime
@@ -94,7 +95,8 @@ import Streamly.Internal.Data.SVar (MonadAsync, Rate (..))
94import Streamly.Internal.Data.Stream.IsStream.Enumeration
95import Streamly.Internal.Data.Stream.IsStream.Enumeration
95 (Enumerable(..), enumerate, enumerateTo)
96 (Enumerable(..), enumerate, enumerateTo)
96import Streamly.Internal.Data.Stream.IsStream.Common
97import Streamly.Internal.Data.Stream.IsStream.Common
97− (absTimesWith, concatM, relTimesWith, timesWith, yield, yieldM, repeatM)
98+ ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, yield, yieldM
99+ , repeatM)
98import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
100import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
99import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
101import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
100import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM))
102import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM))
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+8−8
@@ -166,7 +166,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
166 , repeatM
166 , repeatM
167 , scanlMAfter'
167 , scanlMAfter'
168 , splitOnSeq
168 , splitOnSeq
169− , yield)
169+ , fromPure)
170import Streamly.Internal.Data.Stream.StreamK (IsStream)
170import Streamly.Internal.Data.Stream.StreamK (IsStream)
171import Streamly.Internal.Data.Time.Units
171import Streamly.Internal.Data.Time.Units
172 ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
172 ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
@@ -573,11 +573,11 @@ groups = groupsBy (==)
573--
573--
574-- splitOn is an inverse of intercalating single element:
574-- splitOn is an inverse of intercalating single element:
575--
575--
576−-- @Stream.intercalate (Stream.yield '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@
576+-- @Stream.intercalate (Stream.fromPure '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@
577--
577--
578-- Assuming the input stream does not contain the separator:
578-- Assuming the input stream does not contain the separator:
579--
579--
580−-- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.yield '.') Unfold.fromList === id@
580+-- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.fromPure '.') Unfold.fromList === id@
581--
581--
582-- @since 0.7.0
582-- @since 0.7.0
583
583
@@ -639,11 +639,11 @@ splitOn predicate f =
639--
639--
640-- 'splitOnSuffix' is an inverse of 'intercalateSuffix' with a single element:
640-- 'splitOnSuffix' is an inverse of 'intercalateSuffix' with a single element:
641--
641--
642−-- @Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@
642+-- @Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@
643--
643--
644-- Assuming the input stream does not contain the separator:
644-- Assuming the input stream does not contain the separator:
645--
645--
646−-- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList === id@
646+-- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList === id@
647--
647--
648-- @since 0.7.0
648-- @since 0.7.0
649
649
@@ -695,11 +695,11 @@ splitOnSuffix predicate f = foldMany (FL.takeEndBy_ predicate f)
695--
695--
696-- 'splitOnPrefix' is an inverse of 'intercalatePrefix' with a single element:
696-- 'splitOnPrefix' is an inverse of 'intercalatePrefix' with a single element:
697--
697--
698−-- @Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@
698+-- @Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@
699--
699--
700-- Assuming the input stream does not contain the separator:
700-- Assuming the input stream does not contain the separator:
701--
701--
702−-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList === id@
702+-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList === id@
703--
703--
704-- /Unimplemented/
704-- /Unimplemented/
705
705
@@ -1268,7 +1268,7 @@ classifySessionsBy tick reset ejectPred tmout
1268 , sessionEventTime = curTime
1268 , sessionEventTime = curTime
1269 , sessionCount = cnt
1269 , sessionCount = cnt
1270 , sessionKeyValueMap = mp
1270 , sessionKeyValueMap = mp
1271− , sessionOutputStream = yield (key, fb)
1271+ , sessionOutputStream = fromPure (key, fb)
1272 }
1272 }
1273 partial fs1 = do
1273 partial fs1 = do
1274 let acc = Tuple' timestamp fs1
1274 let acc = Tuple' timestamp fs1
src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3
@@ -192,7 +192,7 @@ sampleBurstStart gap =
192{-# INLINE sortBy #-}
192{-# INLINE sortBy #-}
193sortBy :: (IsStream t, Monad m) => (a -> a -> Ordering) -> t m a -> t m a
193sortBy :: (IsStream t, Monad m) => (a -> a -> Ordering) -> t m a -> t m a
194-- XXX creating StreamD and using D.mergeBy may be more efficient due to fusion
194-- XXX creating StreamD and using D.mergeBy may be more efficient due to fusion
195−sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.yield
195+sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.fromPure
196
196
197------------------------------------------------------------------------------
197------------------------------------------------------------------------------
198-- SQL Joins
198-- SQL Joins
@@ -339,7 +339,7 @@ leftJoin eq s1 s2 = Stream.evalStateT (return False) $ do
339 r <- lift get
339 r <- lift get
340 if r
340 if r
341 then StreamK.nil
341 then StreamK.nil
342− else StreamK.yield Nothing
342+ else StreamK.fromPure Nothing
343 b <- fmap Just (Stream.liftInner s2) <> final
343 b <- fmap Just (Stream.liftInner s2) <> final
344 case b of
344 case b of
345 Just b1 ->
345 Just b1 ->
@@ -416,7 +416,7 @@ outerJoin eq s1 s =
416 r <- lift get
416 r <- lift get
417 if r
417 if r
418 then StreamK.nil
418 then StreamK.nil
419− else StreamK.yield Nothing
419+ else StreamK.fromPure Nothing
420 (_i, b) <-
420 (_i, b) <-
421 Stream.indexed
421 Stream.indexed
422 $ fmap Just (Stream.liftInner (Array.toStream arr)) <> final
422 $ fmap Just (Stream.liftInner (Array.toStream arr)) <> final
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+1−1
@@ -1092,7 +1092,7 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
1092-- @stream@ that is less than @elem@ when compared using @cmp@.
1092-- @stream@ that is less than @elem@ when compared using @cmp@.
1093--
1093--
1094-- @
1094-- @
1095−-- insertBy cmp x = 'mergeBy' cmp ('yield' x)
1095+-- insertBy cmp x = 'mergeBy' cmp ('fromPure' x)
1096-- @
1096-- @
1097--
1097--
1098-- @
1098-- @
src/Streamly/Internal/Data/Stream/Parallel.hs+1−1
@@ -554,7 +554,7 @@ apParallel (ParallelT m1) (ParallelT m2) =
554
554
555instance (Monad m, MonadAsync m) => Applicative (ParallelT m) where
555instance (Monad m, MonadAsync m) => Applicative (ParallelT m) where
556 {-# INLINE pure #-}
556 {-# INLINE pure #-}
557− pure = ParallelT . K.yield
557+ pure = ParallelT . K.fromPure
558 {-# INLINE (<*>) #-}
558 {-# INLINE (<*>) #-}
559 (<*>) = apParallel
559 (<*>) = apParallel
560
560
src/Streamly/Internal/Data/Stream/Serial.hs+3−3
@@ -162,7 +162,7 @@ instance Monad m => Monad (SerialT m) where
162 -- Benchmarks better with StreamD bind and pure:
162 -- Benchmarks better with StreamD bind and pure:
163 -- toList, filterAllout, *>, *<, >> (~2x)
163 -- toList, filterAllout, *>, *<, >> (~2x)
164 --
164 --
165− -- pure = SerialT . D.fromStreamD . D.yield
165+ -- pure = SerialT . D.fromStreamD . D.fromPure
166 -- m >>= f = D.fromStreamD $ D.concatMap (D.toStreamD . f) (D.toStreamD m)
166 -- m >>= f = D.fromStreamD $ D.concatMap (D.toStreamD . f) (D.toStreamD m)
167
167
168 -- Benchmarks better with CPS bind and pure:
168 -- Benchmarks better with CPS bind and pure:
@@ -219,7 +219,7 @@ apDiscardSnd (SerialT m1) (SerialT m2) =
219-- INLINE them.
219-- INLINE them.
220instance Monad m => Applicative (SerialT m) where
220instance Monad m => Applicative (SerialT m) where
221 {-# INLINE pure #-}
221 {-# INLINE pure #-}
222− pure = SerialT . K.yield
222+ pure = SerialT . K.fromPure
223
223
224 {-# INLINE (<*>) #-}
224 {-# INLINE (<*>) #-}
225 (<*>) = apSerial
225 (<*>) = apSerial
@@ -450,7 +450,7 @@ apWSerial (WSerialT m1) (WSerialT m2) =
450
450
451instance Monad m => Applicative (WSerialT m) where
451instance Monad m => Applicative (WSerialT m) where
452 {-# INLINE pure #-}
452 {-# INLINE pure #-}
453− pure = WSerialT . K.yield
453+ pure = WSerialT . K.fromPure
454 {-# INLINE (<*>) #-}
454 {-# INLINE (<*>) #-}
455 (<*>) = apWSerial
455 (<*>) = apWSerial
456
456
src/Streamly/Internal/Data/Stream/StreamD/Generate.hs+1−1
@@ -38,7 +38,7 @@ module Streamly.Internal.Data.Stream.StreamD.Generate
38 , unfoldrM
38 , unfoldrM
39
39
40 -- * From Values
40 -- * From Values
41− , yield
41+ , fromPure
42 , yieldM
42 , yieldM
43 , repeat
43 , repeat
44 , repeatM
44 , repeatM
src/Streamly/Internal/Data/Stream/StreamD/Step.hs+2−2
@@ -28,8 +28,8 @@ instance Functor (Step s) where
28 fmap _ Stop = Stop
28 fmap _ Stop = Stop
29
29
30{-
30{-
31−yield :: Monad m => a -> s -> m (Step s a)
31+fromPure :: Monad m => a -> s -> m (Step s a)
32−yield a = return . Yield a
32+fromPure a = return . Yield a
33
33
34skip :: Monad m => s -> m (Step s a)
34skip :: Monad m => s -> m (Step s a)
35skip = return . Skip
35skip = return . Skip
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6
@@ -30,7 +30,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
30 , unfold
30 , unfold
31
31
32 -- * From Values
32 -- * From Values
33− , yield
33+ , fromPure
34 , yieldM
34 , yieldM
35
35
36 -- * From Containers
36 -- * From Containers
@@ -188,9 +188,9 @@ unfold (Unfold ustep inject) seed = Stream step UnfoldNothing
188------------------------------------------------------------------------------
188------------------------------------------------------------------------------
189
189
190-- | Create a singleton 'Stream' from a pure value.
190-- | Create a singleton 'Stream' from a pure value.
191−{-# INLINE_NORMAL yield #-}
191+{-# INLINE_NORMAL fromPure #-}
192−yield :: Applicative m => a -> Stream m a
192+fromPure :: Applicative m => a -> Stream m a
193−yield x = Stream (\_ s -> pure $ step undefined s) True
193+fromPure x = Stream (\_ s -> pure $ step undefined s) True
194 where
194 where
195 {-# INLINE_LATE step #-}
195 {-# INLINE_LATE step #-}
196 step _ True = Yield x False
196 step _ True = Yield x False
@@ -673,7 +673,7 @@ apDiscardSnd (Stream stepa statea) (Stream stepb stateb) =
673
673
674instance Applicative f => Applicative (Stream f) where
674instance Applicative f => Applicative (Stream f) where
675 {-# INLINE pure #-}
675 {-# INLINE pure #-}
676− pure = yield
676+ pure = fromPure
677
677
678 {-# INLINE (<*>) #-}
678 {-# INLINE (<*>) #-}
679 (<*>) = concatAp
679 (<*>) = concatAp
@@ -728,7 +728,7 @@ unfoldMany (Unfold istep inject) (Stream ostep ost) =
728 Yield x i' -> Yield x (ConcatMapUInner o i')
728 Yield x i' -> Yield x (ConcatMapUInner o i')
729 Skip i' -> Skip (ConcatMapUInner o i')
729 Skip i' -> Skip (ConcatMapUInner o i')
730 Stop -> Skip (ConcatMapUOuter o)
730 Stop -> Skip (ConcatMapUOuter o)
731−
731+
732------------------------------------------------------------------------------
732------------------------------------------------------------------------------
733-- Combine N Streams - concatMap
733-- Combine N Streams - concatMap
734------------------------------------------------------------------------------
734------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/StreamK.hs+5−5
@@ -61,7 +61,7 @@ module Streamly.Internal.Data.Stream.StreamK
61 , iterateM
61 , iterateM
62
62
63 -- ** Conversions
63 -- ** Conversions
64− , yield
64+ , fromPure
65 , yieldM
65 , yieldM
66 , fromFoldable
66 , fromFoldable
67 , fromList
67 , fromList
@@ -272,7 +272,7 @@ once = yieldM
272-- |
272-- |
273-- @
273-- @
274-- repeatM = fix . cons
274-- repeatM = fix . cons
275−-- repeatM = cycle1 . yield
275+-- repeatM = cycle1 . fromPure
276-- @
276-- @
277--
277--
278-- Generate an infinite stream by repeating a monadic value.
278-- Generate an infinite stream by repeating a monadic value.
@@ -929,7 +929,7 @@ intersperseM a m = prependingStart m
929 let yieldk i x = foldStreamShared st yld sng stp $ return i |: go x
929 let yieldk i x = foldStreamShared st yld sng stp $ return i |: go x
930 in foldStream st yieldk sng stp m1
930 in foldStream st yieldk sng stp m1
931 go m2 = mkStream $ \st yld sng stp ->
931 go m2 = mkStream $ \st yld sng stp ->
932− let single i = foldStreamShared st yld sng stp $ a |: yield i
932+ let single i = foldStreamShared st yld sng stp $ a |: fromPure i
933 yieldk i x = foldStreamShared st yld sng stp $ a |: return i |: go x
933 yieldk i x = foldStreamShared st yld sng stp $ a |: return i |: go x
934 in foldStream st yieldk single stp m2
934 in foldStream st yieldk single stp m2
935
935
@@ -943,8 +943,8 @@ insertBy cmp x m = go m
943 where
943 where
944 go m1 = mkStream $ \st yld _ _ ->
944 go m1 = mkStream $ \st yld _ _ ->
945 let single a = case cmp x a of
945 let single a = case cmp x a of
946− GT -> yld a (yield x)
946+ GT -> yld a (fromPure x)
947− _ -> yld x (yield a)
947+ _ -> yld x (fromPure a)
948 stop = yld x nil
948 stop = yld x nil
949 yieldk a r = case cmp x a of
949 yieldk a r = case cmp x a of
950 GT -> yld a (go r)
950 GT -> yld a (go r)
src/Streamly/Internal/Data/Stream/StreamK/Type.hs+7−7
@@ -55,7 +55,7 @@ module Streamly.Internal.Data.Stream.StreamK.Type
55 , consMStream
55 , consMStream
56 , consMBy
56 , consMBy
57 , yieldM
57 , yieldM
58− , yield
58+ , fromPure
59
59
60 , nil
60 , nil
61 , nilM
61 , nilM
@@ -345,9 +345,9 @@ nil = mkStream $ \_ _ _ stp -> stp
345nilM :: (IsStream t, Monad m) => m b -> t m a
345nilM :: (IsStream t, Monad m) => m b -> t m a
346nilM m = mkStream $ \_ _ _ stp -> m >> stp
346nilM m = mkStream $ \_ _ _ stp -> m >> stp
347
347
348−{-# INLINE_NORMAL yield #-}
348+{-# INLINE_NORMAL fromPure #-}
349−yield :: IsStream t => a -> t m a
349+fromPure :: IsStream t => a -> t m a
350−yield a = mkStream $ \_ _ single _ -> single a
350+fromPure a = mkStream $ \_ _ single _ -> single a
351
351
352{-# INLINE_NORMAL yieldM #-}
352{-# INLINE_NORMAL yieldM #-}
353yieldM :: (Monad m, IsStream t) => m a -> t m a
353yieldM :: (Monad m, IsStream t) => m a -> t m a
@@ -487,7 +487,7 @@ foldrSShared = foldrSWith foldStreamShared
487{-# RULES "foldrSShared/nil"
487{-# RULES "foldrSShared/nil"
488 forall k z. foldrSShared k z nil = z #-}
488 forall k z. foldrSShared k z nil = z #-}
489{-# RULES "foldrSShared/single"
489{-# RULES "foldrSShared/single"
490− forall k z x. foldrSShared k z (yield x) = k x z #-}
490+ forall k z x. foldrSShared k z (fromPure x) = k x z #-}
491-- {-# RULES "foldrSShared/app" [1]
491-- {-# RULES "foldrSShared/app" [1]
492-- forall ys. foldrSShared consM ys = \xs -> xs `conjoin` ys #-}
492-- forall ys. foldrSShared consM ys = \xs -> xs `conjoin` ys #-}
493
493
@@ -501,7 +501,7 @@ foldrS = foldrSWith foldStream
501-- See notes in GHC.Base about this rule
501-- See notes in GHC.Base about this rule
502-- {-# RULES "foldr/cons"
502-- {-# RULES "foldr/cons"
503-- forall k z x xs. foldrS k z (x `cons` xs) = k x (foldrS k z xs) #-}
503-- forall k z x xs. foldrS k z (x `cons` xs) = k x (foldrS k z xs) #-}
504−{-# RULES "foldrS/single" forall k z x. foldrS k z (yield x) = k x z #-}
504+{-# RULES "foldrS/single" forall k z x. foldrS k z (fromPure x) = k x z #-}
505-- {-# RULES "foldrS/app" [1]
505-- {-# RULES "foldrS/app" [1]
506-- forall ys. foldrS cons ys = \xs -> xs `conjoin` ys #-}
506-- forall ys. foldrS cons ys = \xs -> xs `conjoin` ys #-}
507
507
@@ -1173,7 +1173,7 @@ concatPairsWith combine f = go Nothing
1173
1173
1174instance Monad m => Applicative (Stream m) where
1174instance Monad m => Applicative (Stream m) where
1175 {-# INLINE pure #-}
1175 {-# INLINE pure #-}
1176− pure = yield
1176+ pure = fromPure
1177 {-# INLINE (<*>) #-}
1177 {-# INLINE (<*>) #-}
1178 (<*>) = ap
1178 (<*>) = ap
1179
1179
src/Streamly/Prelude.hs+4−3
@@ -347,7 +347,7 @@ module Streamly.Prelude
347
347
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− , yield
350+ , fromPure
351 , yieldM
351 , yieldM
352 , repeat
352 , repeat
353 , repeatM
353 , repeatM
@@ -775,12 +775,12 @@ module Streamly.Prelude
775 -- One dimension loops are just a special case of nested loops. For
775 -- One dimension loops are just a special case of nested loops. For
776 -- example, 'concatMap' can degenerate to a simple map operation:
776 -- example, 'concatMap' can degenerate to a simple map operation:
777 --
777 --
778− -- > map f m = S.concatMap (\x -> S.yield (f x)) m
778+ -- > map f m = S.concatMap (\x -> S.fromPure (f x)) m
779 --
779 --
780 -- Similarly, 'concatMap' can perform filtering by mapping an element to a
780 -- Similarly, 'concatMap' can perform filtering by mapping an element to a
781 -- 'nil' stream:
781 -- 'nil' stream:
782 --
782 --
783− -- > filter p m = S.concatMap (\x -> if p x then S.yield x else S.nil) m
783+ -- > filter p m = S.concatMap (\x -> if p x then S.fromPure x else S.nil) m
784 --
784 --
785
785
786 , concatMapWith
786 , concatMapWith
@@ -920,6 +920,7 @@ module Streamly.Prelude
920
920
921 -- * Deprecated
921 -- * Deprecated
922 , once
922 , once
923+ , yield
923 , each
924 , each
924 , scanx
925 , scanx
925 , foldx
926 , foldx
src/Streamly/Tutorial.hs+4−4
@@ -24,7 +24,7 @@
24-- used to fine tune the concurrency control.
24-- used to fine tune the concurrency control.
25--
25--
26-- Streaming and concurrency together enable expressing reactive applications
26-- Streaming and concurrency together enable expressing reactive applications
27−-- conveniently. See the @CirclingSquare@ example in
27+-- conveniently. See the @CirclingSquare@ example in
28-- <https://github.com/composewell/streamly-examples Streamly Examples> for
28-- <https://github.com/composewell/streamly-examples Streamly Examples> for
29-- a simple SDL based FRP example. To summarize, streamly provides a unified
29-- a simple SDL based FRP example. To summarize, streamly provides a unified
30-- computing framework for streaming, non-determinism and functional reactive
30-- computing framework for streaming, non-determinism and functional reactive
@@ -363,7 +363,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
363-- ["hello","world"]
363-- ["hello","world"]
364-- @
364-- @
365--
365--
366−-- To create a singleton stream from a pure value use 'yield' 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 'yieldM'. 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.
@@ -371,7 +371,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
371-- @
371-- @
372-- > S.'toList' $ 'pure' 1
372-- > S.'toList' $ 'pure' 1
373-- [1]
373-- [1]
374−-- > S.'toList' $ S.'yield' 1
374+-- > S.'toList' $ S.'fromPure' 1
375-- [1]
375-- [1]
376-- > S.'toList' $ S.'yieldM' 'getLine'
376-- > S.'toList' $ S.'yieldM' 'getLine'
377-- hello
377-- hello
@@ -1513,7 +1513,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1513-- void $ runStateT runGame 60
1513-- void $ runStateT runGame 60
1514-- @
1514-- @
1515--
1515--
1516−-- You can also find the source of this example in the streamly-examples repo
1516+-- You can also find the source of this example in the streamly-examples repo
1517-- as <https://github.com/composewell/streamly-examples/tree/master/AcidRain.hs AcidRain.hs>.
1517-- as <https://github.com/composewell/streamly-examples/tree/master/AcidRain.hs AcidRain.hs>.
1518-- It has been adapted from Gabriel's
1518-- It has been adapted from Gabriel's
1519-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
1519-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>
test/Streamly/Test/Prelude/Serial.hs+1−1
@@ -558,7 +558,7 @@ main = hspec
558 serialOps $ prop "serially fromList" . constructWithFromList id
558 serialOps $ prop "serially fromList" . constructWithFromList id
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 yield" . constructWithYield id
561+ serialOps $ prop "serially fromPure" . constructWithYield id
562 serialOps $ prop "serially yieldM" . constructWithYieldM id
562 serialOps $ prop "serially yieldM" . constructWithYieldM 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
test/Streamly/Test/Unicode/Stream.hs+1−1
@@ -121,7 +121,7 @@ testLinesArray =
121 xs <- S.toList
121 xs <- S.toList
122 $ S.map A.toList
122 $ S.map A.toList
123 $ AS.splitOnSuffix 10
123 $ AS.splitOnSuffix 10
124− $ S.yield (A.fromList list)
124+ $ S.fromPure (A.fromList list)
125 assert (xs == map (map (fromIntegral . ord))
125 assert (xs == map (map (fromIntegral . ord))
126 (lines (map (chr . fromIntegral) list)))
126 (lines (map (chr . fromIntegral) list)))
127
127
test/lib/Streamly/Test/Prelude/Common.hs+2−2
@@ -411,7 +411,7 @@ constructWithYield listT op len =
411 strm <-
411 strm <-
412 run
412 run
413 $ S.toList . op . S.take (fromIntegral len)
413 $ S.toList . op . S.take (fromIntegral len)
414− $ foldMap S.yield (repeat 0)
414+ $ foldMap S.fromPure (repeat 0)
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
@@ -446,7 +446,7 @@ simpleProps constr op a = monadicIO $ do
446
446
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 "yield a = a" $ simpleProps S.yield op
449+ prop "fromPure a = a" $ simpleProps S.fromPure op
450 prop "yieldM a = a" $ simpleProps (S.yieldM . return) op
450 prop "yieldM a = a" $ simpleProps (S.yieldM . return) op
451
451
452-------------------------------------------------------------------------------
452-------------------------------------------------------------------------------