on master help sign in
Rename Streamly.Prelude.yield to fromPure.

- Deprecate yield.

commit4dfc6bf9ee635e74398f17f03083bb434436519f authorPranay Sashank <pranaysashank@composewell.com> dateSat 29 May 2021, 00:51 (5 years ago) parent1630d3c
28 files changed+102−85
Changelog.md+3−1 benchmark/Streamly/Benchmark/Data/Parser.hs+1−1 benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+1−1 benchmark/Streamly/Benchmark/Data/Stream/StreamDK.hs+1−1 benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+1−1 benchmark/lib/Streamly/Benchmark/Prelude.hs+4−4 design/cps-vs-direct.rst+4−4 src/Streamly/Internal/Data/Sink.hs+1−1 src/Streamly/Internal/Data/Stream/Ahead.hs+1−1 src/Streamly/Internal/Data/Stream/Async.hs+2−2 src/Streamly/Internal/Data/Stream/IsStream/Common.hs+24−12 src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+6−6 src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−2 src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+8−8 src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3 src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+1−1 src/Streamly/Internal/Data/Stream/Parallel.hs+1−1 src/Streamly/Internal/Data/Stream/Serial.hs+3−3 src/Streamly/Internal/Data/Stream/StreamD/Generate.hs+1−1 src/Streamly/Internal/Data/Stream/StreamD/Step.hs+2−2 src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6 src/Streamly/Internal/Data/Stream/StreamK.hs+5−5 src/Streamly/Internal/Data/Stream/StreamK/Type.hs+7−7 src/Streamly/Prelude.hs+4−3 src/Streamly/Tutorial.hs+4−4 test/Streamly/Test/Prelude/Serial.hs+1−1 test/Streamly/Test/Unicode/Stream.hs+1−1 test/lib/Streamly/Test/Prelude/Common.hs+2−2
Changelog.md+3−1
@@ -90,7 +90,9 @@
9090 * `foldMapWith` to `concatMapFoldableWith`
9191 * `forEachWith` to `concatForFoldableWith`
9292 * `serially` to `fromSerial` and so on
93−* In `Streamly.Prelude`, `concatUnfold` is renamed to `unfoldMany`
93+* In `Streamly.Prelude` the following functions have been renamed:
94+ * `concatUnfold` to `unfoldMany`
95+ * `yield` to `fromPure`
9496* The following encoding/decoding routines have been renamed:
9597 * `encodeUtf8Lax` to `encodeUtf8`
9698 * `encodeLatin1Lax` to `encodeLatin1`
benchmark/Streamly/Benchmark/Data/Parser.hs+1−1
@@ -89,7 +89,7 @@ drainWhile value = IP.parse (PR.drainWhile (<= value))
8989{-# INLINE sliceBeginWith #-}
9090sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
9191sliceBeginWith 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
9393 let stream2 = value `S.cons` stream1
9494 IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2
9595
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+1−1
@@ -71,7 +71,7 @@ drainWhile p = PR.takeWhile p FL.drain
7171{-# INLINE sliceBeginWith #-}
7272sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
7373sliceBeginWith 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
7575 let stream2 = value `S.cons` stream1
7676 IP.parseD (PR.sliceBeginWith (== value) FL.drain) stream2
7777
benchmark/Streamly/Benchmark/Data/Stream/StreamDK.hs+1−1
@@ -104,7 +104,7 @@ sourceFromFoldableM n = S.fromFoldableM (Prelude.fmap return [n..n+value])
104104{-
105105{-# INLINE sourceFoldMapWith #-}
106106sourceFoldMapWith :: 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]
108108
109109{-# INLINE sourceFoldMapWithM #-}
110110sourceFoldMapWithM :: 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
154154
155155{-# INLINE concatMapFoldableSerial #-}
156156concatMapFoldableSerial :: 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]
158158
159159{-# INLINE concatMapFoldableSerialM #-}
160160concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int
benchmark/lib/Streamly/Benchmark/Prelude.hs+4−4
@@ -294,13 +294,13 @@ transformZipMapM t n =
294294{-# INLINE sourceFoldMapWith #-}
295295sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
296296 => 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]
298298
299299{-# INLINE concatForFoldableWith #-}
300300concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int))
301301 => Int -> Int -> t m Int
302302concatForFoldableWith value n =
303− S.concatForFoldableWith (<>) [n..n+value] S.yield
303+ S.concatForFoldableWith (<>) [n..n+value] S.fromPure
304304
305305{-# INLINE concatFoldableWith #-}
306306concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
@@ -308,7 +308,7 @@ concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
308308concatFoldableWith value n =
309309 let step x =
310310 if x <= n + value
311− then Just (S.yield x, x + 1)
311+ then Just (S.fromPure x, x + 1)
312312 else Nothing
313313 list = List.unfoldr step n
314314 in S.concatFoldableWith (<>) list
@@ -316,7 +316,7 @@ concatFoldableWith value n =
316316{-# INLINE sourceFoldMapWithStream #-}
317317sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
318318 => Int -> Int -> t m Int
319−sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.yield
319+sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.fromPure
320320 $ (S.enumerateFromTo n (n + value) :: S.SerialT Identity Int)
321321
322322{-# INLINE sourceFoldMapWithM #-}
design/cps-vs-direct.rst+4−4
@@ -21,8 +21,8 @@ Generating
2121 nil = Stream (const (return Stop)) ()
2222
2323 -- | A single value
24− yield :: Applicative m => a -> Stream m a
25− yield x = Stream step True
24+ fromPure :: Applicative m => a -> Stream m a
25+ fromPure x = Stream step True
2626
2727 where
2828
@@ -204,8 +204,8 @@ Generating
204204 nil :: Stream m a
205205 nil = Stream $ \_ stp -> stp
206206
207− yield :: a -> Stream m a
208− yield a = Stream $ \yield _ -> yield a nil
207+ fromPure :: a -> Stream m a
208+ fromPure a = Stream $ \yield _ -> yield a nil
209209
210210 cons :: a -> Stream m a -> Stream m a
211211 cons a r = Stream $ \yld _ -> yld a r
src/Streamly/Internal/Data/Sink.hs+1−1
@@ -190,7 +190,7 @@ demux kv = Sink step
190190-- @
191191-- @
192192-- > 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))
194194-- L 1
195195-- R 2
196196-- @
src/Streamly/Internal/Data/Stream/Ahead.hs+1−1
@@ -786,7 +786,7 @@ apAhead (AheadT m1) (AheadT m2) =
786786
787787instance (Monad m, MonadAsync m) => Applicative (AheadT m) where
788788 {-# INLINE pure #-}
789− pure = AheadT . K.yield
789+ pure = AheadT . K.fromPure
790790 {-# INLINE (<*>) #-}
791791 (<*>) = apAhead
792792
src/Streamly/Internal/Data/Stream/Async.hs+2−2
@@ -844,7 +844,7 @@ apAsync (AsyncT m1) (AsyncT m2) =
844844
845845instance (Monad m, MonadAsync m) => Applicative (AsyncT m) where
846846 {-# INLINE pure #-}
847− pure = AsyncT . K.yield
847+ pure = AsyncT . K.fromPure
848848 {-# INLINE (<*>) #-}
849849 (<*>) = apAsync
850850
@@ -1143,7 +1143,7 @@ apWAsync (WAsyncT m1) (WAsyncT m2) =
11431143-- GHC: if we specify arguments in the definition of (<*>) we see a significant
11441144-- performance degradation (~2x).
11451145instance (Monad m, MonadAsync m) => Applicative (WAsyncT m) where
1146− pure = WAsyncT . K.yield
1146+ pure = WAsyncT . K.fromPure
11471147 (<*>) = apWAsync
11481148
11491149------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+24−12
@@ -14,7 +14,7 @@
1414module Streamly.Internal.Data.Stream.IsStream.Common
1515 (
1616 -- * Generation
17− yield
17+ fromPure
1818 , yieldM
1919 , repeatM
2020 , timesWith
@@ -44,6 +44,9 @@ module Streamly.Internal.Data.Stream.IsStream.Common
4444 , concatMapM
4545 , concatMap
4646 , splitOnSeq
47+
48+ -- * Deprecated
49+ , yield
4750 )
4851where
4952
@@ -92,7 +95,7 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
9295--
9396-- |
9497-- @
95−-- yield a = a \`cons` nil
98+-- fromPure a = a \`cons` nil
9699-- @
97100--
98101-- Create a singleton stream from a pure value.
@@ -100,19 +103,20 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
100103-- The following holds in monadic streams, but not in Zip streams:
101104--
102105-- @
103−-- yield = pure
104−-- yield = yieldM . pure
106+-- fromPure = pure
107+-- fromPure = yieldM . pure
105108-- @
106109--
107−-- In Zip applicative streams 'yield' is not the same as 'pure' because in that
108−-- case 'pure' is equivalent to 'repeat' instead. 'yield' and 'pure' are
109−-- equally efficient, in other cases 'yield' may be slightly more efficient
110+-- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
111+-- case 'pure' is equivalent to 'repeat' instead. 'fromPure' and 'pure' are
112+-- equally efficient, in other cases 'fromPure' may be slightly more efficient
110113-- than the other equivalent definitions.
111114--
112−-- @since 0.4.0
113−{-# INLINE yield #-}
114−yield :: IsStream t => a -> t m a
115−yield = K.yield
115+-- /Since: 0.8.0 (Renamed yield to fromPure)/
116+--
117+{-# INLINE fromPure #-}
118+fromPure :: IsStream t => a -> t m a
119+fromPure = K.fromPure
116120
117121-- |
118122-- @
@@ -484,7 +488,7 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
484488--
485489{-# INLINE concatM #-}
486490concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
487−concatM generator = concatMapM (\() -> generator) (yield ())
491+concatM generator = concatMapM (\() -> generator) (fromPure ())
488492
489493------------------------------------------------------------------------------
490494-- Split stream and fold
@@ -545,3 +549,11 @@ splitOnSeq
545549 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
546550 => Array a -> Fold m a b -> t m a -> t m b
547551splitOnSeq 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
161161import Streamly.Internal.Data.Stream.Ahead (ahead)
162162import Streamly.Internal.Data.Stream.Async (async, wAsync)
163163import Streamly.Internal.Data.Stream.IsStream.Common
164− (concatM, concatMapM, concatMap, smapM, yield, yieldM)
164+ (concatM, concatMapM, concatMap, smapM, fromPure, yieldM)
165165import Streamly.Internal.Data.Stream.Parallel (parallel)
166166import Streamly.Internal.Data.Stream.Prelude
167167 ( concatFoldableWith, concatMapFoldableWith
@@ -685,7 +685,7 @@ concatMapEitherWith = undefined
685685--
686686-- For example, you can sort a stream using merge sort like this:
687687--
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]
689689-- [1,2,5,7,9]
690690--
691691-- /Caution: the stream of streams must be finite/
@@ -723,7 +723,7 @@ concatPairsWith = K.concatPairsWith
723723-- @
724724-- Stream.iterateMapWith Stream.serial
725725-- (either Dir.toEither (const nil))
726−-- (yield (Left "tmp"))
726+-- (fromPure (Left "tmp"))
727727-- @
728728--
729729-- /Pre-release/
@@ -737,7 +737,7 @@ iterateMapWith
737737 -> t m a
738738iterateMapWith combine f = concatMapWith combine go
739739 where
740− go x = yield x `combine` concatMapWith combine go (f x)
740+ go x = fromPure x `combine` concatMapWith combine go (f x)
741741
742742{-
743743{-# INLINE iterateUnfold #-}
@@ -778,7 +778,7 @@ iterateSmapMWith combine f initial stream =
778778
779779 where
780780
781− go b a = yield a `combine` feedback b a
781+ go b a = fromPure a `combine` feedback b a
782782
783783 feedback b a =
784784 concatMap
@@ -799,7 +799,7 @@ iterateSmapMWith combine f initial stream =
799799-- To traverse a directory tree:
800800--
801801-- @
802−-- iterateMapLeftsWith serial Dir.toEither (yield (Left "tmp"))
802+-- iterateMapLeftsWith serial Dir.toEither (fromPure (Left "tmp"))
803803-- @
804804--
805805-- /Pre-release/
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−2
@@ -35,7 +35,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
3535 , unfoldrM
3636
3737 -- * From Values
38− , yield
38+ , fromPure
3939 , yieldM
4040 , repeat
4141 , repeatM
@@ -79,6 +79,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
7979
8080 -- * Deprecated
8181 , K.once
82+ , yield
8283 , each
8384 , fromHandle
8485 , currentTime
@@ -94,7 +95,8 @@ import Streamly.Internal.Data.SVar (MonadAsync, Rate (..))
9495import Streamly.Internal.Data.Stream.IsStream.Enumeration
9596 (Enumerable(..), enumerate, enumerateTo)
9697import Streamly.Internal.Data.Stream.IsStream.Common
97− (absTimesWith, concatM, relTimesWith, timesWith, yield, yieldM, repeatM)
98+ ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, yield, yieldM
99+ , repeatM)
98100import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
99101import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
100102import 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
166166 , repeatM
167167 , scanlMAfter'
168168 , splitOnSeq
169− , yield)
169+ , fromPure)
170170import Streamly.Internal.Data.Stream.StreamK (IsStream)
171171import Streamly.Internal.Data.Time.Units
172172 ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
@@ -573,11 +573,11 @@ groups = groupsBy (==)
573573--
574574-- splitOn is an inverse of intercalating single element:
575575--
576−-- @Stream.intercalate (Stream.yield '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@
576+-- @Stream.intercalate (Stream.fromPure '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@
577577--
578578-- Assuming the input stream does not contain the separator:
579579--
580−-- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.yield '.') Unfold.fromList === id@
580+-- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.fromPure '.') Unfold.fromList === id@
581581--
582582-- @since 0.7.0
583583
@@ -639,11 +639,11 @@ splitOn predicate f =
639639--
640640-- 'splitOnSuffix' is an inverse of 'intercalateSuffix' with a single element:
641641--
642−-- @Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@
642+-- @Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@
643643--
644644-- Assuming the input stream does not contain the separator:
645645--
646−-- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList === id@
646+-- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList === id@
647647--
648648-- @since 0.7.0
649649
@@ -695,11 +695,11 @@ splitOnSuffix predicate f = foldMany (FL.takeEndBy_ predicate f)
695695--
696696-- 'splitOnPrefix' is an inverse of 'intercalatePrefix' with a single element:
697697--
698−-- @Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@
698+-- @Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@
699699--
700700-- Assuming the input stream does not contain the separator:
701701--
702−-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList === id@
702+-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList === id@
703703--
704704-- /Unimplemented/
705705
@@ -1268,7 +1268,7 @@ classifySessionsBy tick reset ejectPred tmout
12681268 , sessionEventTime = curTime
12691269 , sessionCount = cnt
12701270 , sessionKeyValueMap = mp
1271− , sessionOutputStream = yield (key, fb)
1271+ , sessionOutputStream = fromPure (key, fb)
12721272 }
12731273 partial fs1 = do
12741274 let acc = Tuple' timestamp fs1
src/Streamly/Internal/Data/Stream/IsStream/Top.hs+3−3
@@ -192,7 +192,7 @@ sampleBurstStart gap =
192192{-# INLINE sortBy #-}
193193sortBy :: (IsStream t, Monad m) => (a -> a -> Ordering) -> t m a -> t m a
194194-- 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
196196
197197------------------------------------------------------------------------------
198198-- SQL Joins
@@ -339,7 +339,7 @@ leftJoin eq s1 s2 = Stream.evalStateT (return False) $ do
339339 r <- lift get
340340 if r
341341 then StreamK.nil
342− else StreamK.yield Nothing
342+ else StreamK.fromPure Nothing
343343 b <- fmap Just (Stream.liftInner s2) <> final
344344 case b of
345345 Just b1 ->
@@ -416,7 +416,7 @@ outerJoin eq s1 s =
416416 r <- lift get
417417 if r
418418 then StreamK.nil
419− else StreamK.yield Nothing
419+ else StreamK.fromPure Nothing
420420 (_i, b) <-
421421 Stream.indexed
422422 $ 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
10921092-- @stream@ that is less than @elem@ when compared using @cmp@.
10931093--
10941094-- @
1095−-- insertBy cmp x = 'mergeBy' cmp ('yield' x)
1095+-- insertBy cmp x = 'mergeBy' cmp ('fromPure' x)
10961096-- @
10971097--
10981098-- @
src/Streamly/Internal/Data/Stream/Parallel.hs+1−1
@@ -554,7 +554,7 @@ apParallel (ParallelT m1) (ParallelT m2) =
554554
555555instance (Monad m, MonadAsync m) => Applicative (ParallelT m) where
556556 {-# INLINE pure #-}
557− pure = ParallelT . K.yield
557+ pure = ParallelT . K.fromPure
558558 {-# INLINE (<*>) #-}
559559 (<*>) = apParallel
560560
src/Streamly/Internal/Data/Stream/Serial.hs+3−3
@@ -162,7 +162,7 @@ instance Monad m => Monad (SerialT m) where
162162 -- Benchmarks better with StreamD bind and pure:
163163 -- toList, filterAllout, *>, *<, >> (~2x)
164164 --
165− -- pure = SerialT . D.fromStreamD . D.yield
165+ -- pure = SerialT . D.fromStreamD . D.fromPure
166166 -- m >>= f = D.fromStreamD $ D.concatMap (D.toStreamD . f) (D.toStreamD m)
167167
168168 -- Benchmarks better with CPS bind and pure:
@@ -219,7 +219,7 @@ apDiscardSnd (SerialT m1) (SerialT m2) =
219219-- INLINE them.
220220instance Monad m => Applicative (SerialT m) where
221221 {-# INLINE pure #-}
222− pure = SerialT . K.yield
222+ pure = SerialT . K.fromPure
223223
224224 {-# INLINE (<*>) #-}
225225 (<*>) = apSerial
@@ -450,7 +450,7 @@ apWSerial (WSerialT m1) (WSerialT m2) =
450450
451451instance Monad m => Applicative (WSerialT m) where
452452 {-# INLINE pure #-}
453− pure = WSerialT . K.yield
453+ pure = WSerialT . K.fromPure
454454 {-# INLINE (<*>) #-}
455455 (<*>) = apWSerial
456456
src/Streamly/Internal/Data/Stream/StreamD/Generate.hs+1−1
@@ -38,7 +38,7 @@ module Streamly.Internal.Data.Stream.StreamD.Generate
3838 , unfoldrM
3939
4040 -- * From Values
41− , yield
41+ , fromPure
4242 , yieldM
4343 , repeat
4444 , repeatM
src/Streamly/Internal/Data/Stream/StreamD/Step.hs+2−2
@@ -28,8 +28,8 @@ instance Functor (Step s) where
2828 fmap _ Stop = Stop
2929
3030{-
31−yield :: Monad m => a -> s -> m (Step s a)
32−yield a = return . Yield a
31+fromPure :: Monad m => a -> s -> m (Step s a)
32+fromPure a = return . Yield a
3333
3434skip :: Monad m => s -> m (Step s a)
3535skip = return . Skip
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6
@@ -30,7 +30,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
3030 , unfold
3131
3232 -- * From Values
33− , yield
33+ , fromPure
3434 , yieldM
3535
3636 -- * From Containers
@@ -188,9 +188,9 @@ unfold (Unfold ustep inject) seed = Stream step UnfoldNothing
188188------------------------------------------------------------------------------
189189
190190-- | Create a singleton 'Stream' from a pure value.
191−{-# INLINE_NORMAL yield #-}
192−yield :: Applicative m => a -> Stream m a
193−yield x = Stream (\_ s -> pure $ step undefined s) True
191+{-# INLINE_NORMAL fromPure #-}
192+fromPure :: Applicative m => a -> Stream m a
193+fromPure x = Stream (\_ s -> pure $ step undefined s) True
194194 where
195195 {-# INLINE_LATE step #-}
196196 step _ True = Yield x False
@@ -673,7 +673,7 @@ apDiscardSnd (Stream stepa statea) (Stream stepb stateb) =
673673
674674instance Applicative f => Applicative (Stream f) where
675675 {-# INLINE pure #-}
676− pure = yield
676+ pure = fromPure
677677
678678 {-# INLINE (<*>) #-}
679679 (<*>) = concatAp
@@ -728,7 +728,7 @@ unfoldMany (Unfold istep inject) (Stream ostep ost) =
728728 Yield x i' -> Yield x (ConcatMapUInner o i')
729729 Skip i' -> Skip (ConcatMapUInner o i')
730730 Stop -> Skip (ConcatMapUOuter o)
731−
731+
732732------------------------------------------------------------------------------
733733-- Combine N Streams - concatMap
734734------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/StreamK.hs+5−5
@@ -61,7 +61,7 @@ module Streamly.Internal.Data.Stream.StreamK
6161 , iterateM
6262
6363 -- ** Conversions
64− , yield
64+ , fromPure
6565 , yieldM
6666 , fromFoldable
6767 , fromList
@@ -272,7 +272,7 @@ once = yieldM
272272-- |
273273-- @
274274-- repeatM = fix . cons
275−-- repeatM = cycle1 . yield
275+-- repeatM = cycle1 . fromPure
276276-- @
277277--
278278-- Generate an infinite stream by repeating a monadic value.
@@ -929,7 +929,7 @@ intersperseM a m = prependingStart m
929929 let yieldk i x = foldStreamShared st yld sng stp $ return i |: go x
930930 in foldStream st yieldk sng stp m1
931931 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
933933 yieldk i x = foldStreamShared st yld sng stp $ a |: return i |: go x
934934 in foldStream st yieldk single stp m2
935935
@@ -943,8 +943,8 @@ insertBy cmp x m = go m
943943 where
944944 go m1 = mkStream $ \st yld _ _ ->
945945 let single a = case cmp x a of
946− GT -> yld a (yield x)
947− _ -> yld x (yield a)
946+ GT -> yld a (fromPure x)
947+ _ -> yld x (fromPure a)
948948 stop = yld x nil
949949 yieldk a r = case cmp x a of
950950 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
5555 , consMStream
5656 , consMBy
5757 , yieldM
58− , yield
58+ , fromPure
5959
6060 , nil
6161 , nilM
@@ -345,9 +345,9 @@ nil = mkStream $ \_ _ _ stp -> stp
345345nilM :: (IsStream t, Monad m) => m b -> t m a
346346nilM m = mkStream $ \_ _ _ stp -> m >> stp
347347
348−{-# INLINE_NORMAL yield #-}
349−yield :: IsStream t => a -> t m a
350−yield a = mkStream $ \_ _ single _ -> single a
348+{-# INLINE_NORMAL fromPure #-}
349+fromPure :: IsStream t => a -> t m a
350+fromPure a = mkStream $ \_ _ single _ -> single a
351351
352352{-# INLINE_NORMAL yieldM #-}
353353yieldM :: (Monad m, IsStream t) => m a -> t m a
@@ -487,7 +487,7 @@ foldrSShared = foldrSWith foldStreamShared
487487{-# RULES "foldrSShared/nil"
488488 forall k z. foldrSShared k z nil = z #-}
489489{-# 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 #-}
491491-- {-# RULES "foldrSShared/app" [1]
492492-- forall ys. foldrSShared consM ys = \xs -> xs `conjoin` ys #-}
493493
@@ -501,7 +501,7 @@ foldrS = foldrSWith foldStream
501501-- See notes in GHC.Base about this rule
502502-- {-# RULES "foldr/cons"
503503-- 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 #-}
505505-- {-# RULES "foldrS/app" [1]
506506-- forall ys. foldrS cons ys = \xs -> xs `conjoin` ys #-}
507507
@@ -1173,7 +1173,7 @@ concatPairsWith combine f = go Nothing
11731173
11741174instance Monad m => Applicative (Stream m) where
11751175 {-# INLINE pure #-}
1176− pure = yield
1176+ pure = fromPure
11771177 {-# INLINE (<*>) #-}
11781178 (<*>) = ap
11791179
src/Streamly/Prelude.hs+4−3
@@ -347,7 +347,7 @@ module Streamly.Prelude
347347
348348 -- ** From Values
349349 -- | Generate a monadic stream from a seed value or values.
350− , yield
350+ , fromPure
351351 , yieldM
352352 , repeat
353353 , repeatM
@@ -775,12 +775,12 @@ module Streamly.Prelude
775775 -- One dimension loops are just a special case of nested loops. For
776776 -- example, 'concatMap' can degenerate to a simple map operation:
777777 --
778− -- > map f m = S.concatMap (\x -> S.yield (f x)) m
778+ -- > map f m = S.concatMap (\x -> S.fromPure (f x)) m
779779 --
780780 -- Similarly, 'concatMap' can perform filtering by mapping an element to a
781781 -- 'nil' stream:
782782 --
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
784784 --
785785
786786 , concatMapWith
@@ -920,6 +920,7 @@ module Streamly.Prelude
920920
921921 -- * Deprecated
922922 , once
923+ , yield
923924 , each
924925 , scanx
925926 , foldx
src/Streamly/Tutorial.hs+4−4
@@ -24,7 +24,7 @@
2424-- used to fine tune the concurrency control.
2525--
2626-- Streaming and concurrency together enable expressing reactive applications
27−-- conveniently. See the @CirclingSquare@ example in
27+-- conveniently. See the @CirclingSquare@ example in
2828-- <https://github.com/composewell/streamly-examples Streamly Examples> for
2929-- a simple SDL based FRP example. To summarize, streamly provides a unified
3030-- computing framework for streaming, non-determinism and functional reactive
@@ -363,7 +363,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
363363-- ["hello","world"]
364364-- @
365365--
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
367367-- create a singleton stream from a monadic action use 'yieldM'. Note that in
368368-- case of Zip applicative streams "pure" repeats the value to generate an
369369-- infinite stream.
@@ -371,7 +371,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
371371-- @
372372-- > S.'toList' $ 'pure' 1
373373-- [1]
374−-- > S.'toList' $ S.'yield' 1
374+-- > S.'toList' $ S.'fromPure' 1
375375-- [1]
376376-- > S.'toList' $ S.'yieldM' 'getLine'
377377-- hello
@@ -1513,7 +1513,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
15131513-- void $ runStateT runGame 60
15141514-- @
15151515--
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
15171517-- as <https://github.com/composewell/streamly-examples/tree/master/AcidRain.hs AcidRain.hs>.
15181518-- It has been adapted from Gabriel's
15191519-- <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
558558 serialOps $ prop "serially fromList" . constructWithFromList id
559559 serialOps $ prop "serially fromListM" . constructWithFromListM id
560560 serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
561− serialOps $ prop "serially yield" . constructWithYield id
561+ serialOps $ prop "serially fromPure" . constructWithYield id
562562 serialOps $ prop "serially yieldM" . constructWithYieldM id
563563 serialOps $ prop "serially cons" . constructWithCons S.cons
564564 serialOps $ prop "serially consM" . constructWithConsM S.consM id
test/Streamly/Test/Unicode/Stream.hs+1−1
@@ -121,7 +121,7 @@ testLinesArray =
121121 xs <- S.toList
122122 $ S.map A.toList
123123 $ AS.splitOnSuffix 10
124− $ S.yield (A.fromList list)
124+ $ S.fromPure (A.fromList list)
125125 assert (xs == map (map (fromIntegral . ord))
126126 (lines (map (chr . fromIntegral) list)))
127127
test/lib/Streamly/Test/Prelude/Common.hs+2−2
@@ -411,7 +411,7 @@ constructWithYield listT op len =
411411 strm <-
412412 run
413413 $ S.toList . op . S.take (fromIntegral len)
414− $ foldMap S.yield (repeat 0)
414+ $ foldMap S.fromPure (repeat 0)
415415 let list = replicate (fromIntegral len) 0
416416 listEquals (==) (listT strm) list
417417
@@ -446,7 +446,7 @@ simpleProps constr op a = monadicIO $ do
446446
447447simpleOps :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
448448simpleOps op = do
449− prop "yield a = a" $ simpleProps S.yield op
449+ prop "fromPure a = a" $ simpleProps S.fromPure op
450450 prop "yieldM a = a" $ simpleProps (S.yieldM . return) op
451451
452452-------------------------------------------------------------------------------