Rename Streamly.Prelude.yield to fromPure.

- Deprecate yield.
This commit is contained in:
Pranay Sashank 2021-05-29 00:51:50 +05:30
parent 1630d3c952
commit 4dfc6bf9ee
28 changed files with 102 additions and 85 deletions

View File

@ -90,7 +90,9 @@
* `foldMapWith` to `concatMapFoldableWith` * `foldMapWith` to `concatMapFoldableWith`
* `forEachWith` to `concatForFoldableWith` * `forEachWith` to `concatForFoldableWith`
* `serially` to `fromSerial` and so on * `serially` to `fromSerial` and so on
* In `Streamly.Prelude`, `concatUnfold` is renamed to `unfoldMany` * In `Streamly.Prelude` the following functions have been renamed:
* `concatUnfold` to `unfoldMany`
* `yield` to `fromPure`
* The following encoding/decoding routines have been renamed: * The following encoding/decoding routines have been renamed:
* `encodeUtf8Lax` to `encodeUtf8` * `encodeUtf8Lax` to `encodeUtf8`
* `encodeLatin1Lax` to `encodeLatin1` * `encodeLatin1Lax` to `encodeLatin1`

View File

@ -89,7 +89,7 @@ drainWhile value = IP.parse (PR.drainWhile (<= value))
{-# INLINE sliceBeginWith #-} {-# INLINE sliceBeginWith #-}
sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m () sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
sliceBeginWith value stream = do sliceBeginWith value stream = do
stream1 <- return . fromMaybe (S.yield (value + 1)) =<< S.tail stream stream1 <- return . fromMaybe (S.fromPure (value + 1)) =<< S.tail stream
let stream2 = value `S.cons` stream1 let stream2 = value `S.cons` stream1
IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2 IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2

View File

@ -71,7 +71,7 @@ drainWhile p = PR.takeWhile p FL.drain
{-# INLINE sliceBeginWith #-} {-# INLINE sliceBeginWith #-}
sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m () sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
sliceBeginWith value stream = do sliceBeginWith value stream = do
stream1 <- return . fromMaybe (S.yield (value + 1)) =<< S.tail stream stream1 <- return . fromMaybe (S.fromPure (value + 1)) =<< S.tail stream
let stream2 = value `S.cons` stream1 let stream2 = value `S.cons` stream1
IP.parseD (PR.sliceBeginWith (== value) FL.drain) stream2 IP.parseD (PR.sliceBeginWith (== value) FL.drain) stream2

View File

@ -104,7 +104,7 @@ sourceFromFoldableM n = S.fromFoldableM (Prelude.fmap return [n..n+value])
{- {-
{-# INLINE sourceFoldMapWith #-} {-# INLINE sourceFoldMapWith #-}
sourceFoldMapWith :: Int -> Stream m Int sourceFoldMapWith :: Int -> Stream m Int
sourceFoldMapWith n = SP.foldMapWith S.serial S.yield [n..n+value] sourceFoldMapWith n = SP.foldMapWith S.serial S.fromPure [n..n+value]
{-# INLINE sourceFoldMapWithM #-} {-# INLINE sourceFoldMapWithM #-}
sourceFoldMapWithM :: Monad m => Int -> Stream m Int sourceFoldMapWithM :: Monad m => Int -> Stream m Int

View File

@ -154,7 +154,7 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
{-# INLINE concatMapFoldableSerial #-} {-# INLINE concatMapFoldableSerial #-}
concatMapFoldableSerial :: Int -> Int -> Stream m Int concatMapFoldableSerial :: Int -> Int -> Stream m Int
concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.yield [n..n+streamLen] concatMapFoldableSerial streamLen n = concatMapFoldableWith S.serial S.fromPure [n..n+streamLen]
{-# INLINE concatMapFoldableSerialM #-} {-# INLINE concatMapFoldableSerialM #-}
concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int

View File

@ -294,13 +294,13 @@ transformZipMapM t n =
{-# INLINE sourceFoldMapWith #-} {-# INLINE sourceFoldMapWith #-}
sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int)) sourceFoldMapWith :: (S.IsStream t, Semigroup (t m Int))
=> Int -> Int -> t m Int => Int -> Int -> t m Int
sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.yield [n..n+value] sourceFoldMapWith value n = S.concatMapFoldableWith (<>) S.fromPure [n..n+value]
{-# INLINE concatForFoldableWith #-} {-# INLINE concatForFoldableWith #-}
concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int)) concatForFoldableWith :: (S.IsStream t, Semigroup (t m Int))
=> Int -> Int -> t m Int => Int -> Int -> t m Int
concatForFoldableWith value n = concatForFoldableWith value n =
S.concatForFoldableWith (<>) [n..n+value] S.yield S.concatForFoldableWith (<>) [n..n+value] S.fromPure
{-# INLINE concatFoldableWith #-} {-# INLINE concatFoldableWith #-}
concatFoldableWith :: (S.IsStream t, Semigroup (t m Int)) concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
@ -308,7 +308,7 @@ concatFoldableWith :: (S.IsStream t, Semigroup (t m Int))
concatFoldableWith value n = concatFoldableWith value n =
let step x = let step x =
if x <= n + value if x <= n + value
then Just (S.yield x, x + 1) then Just (S.fromPure x, x + 1)
else Nothing else Nothing
list = List.unfoldr step n list = List.unfoldr step n
in S.concatFoldableWith (<>) list in S.concatFoldableWith (<>) list
@ -316,7 +316,7 @@ concatFoldableWith value n =
{-# INLINE sourceFoldMapWithStream #-} {-# INLINE sourceFoldMapWithStream #-}
sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int)) sourceFoldMapWithStream :: (S.IsStream t, Semigroup (t m Int))
=> Int -> Int -> t m Int => Int -> Int -> t m Int
sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.yield sourceFoldMapWithStream value n = S.concatMapFoldableWith (<>) S.fromPure
$ (S.enumerateFromTo n (n + value) :: S.SerialT Identity Int) $ (S.enumerateFromTo n (n + value) :: S.SerialT Identity Int)
{-# INLINE sourceFoldMapWithM #-} {-# INLINE sourceFoldMapWithM #-}

View File

@ -21,8 +21,8 @@ Generating
nil = Stream (const (return Stop)) () nil = Stream (const (return Stop)) ()
-- | A single value -- | A single value
yield :: Applicative m => a -> Stream m a fromPure :: Applicative m => a -> Stream m a
yield x = Stream step True fromPure x = Stream step True
where where
@ -204,8 +204,8 @@ Generating
nil :: Stream m a nil :: Stream m a
nil = Stream $ \_ stp -> stp nil = Stream $ \_ stp -> stp
yield :: a -> Stream m a fromPure :: a -> Stream m a
yield a = Stream $ \yield _ -> yield a nil fromPure a = Stream $ \yield _ -> yield a nil
cons :: a -> Stream m a -> Stream m a cons :: a -> Stream m a -> Stream m a
cons a r = Stream $ \yld _ -> yld a r cons a r = Stream $ \yld _ -> yld a r

View File

@ -190,7 +190,7 @@ demux kv = Sink step
-- @ -- @
-- @ -- @
-- > let pr x = Sink.drainM (putStrLn . ((x ++ " ") ++) . show) -- > let pr x = Sink.drainM (putStrLn . ((x ++ " ") ++) . show)
-- in Sink.sink (Sink.unzip return (pr \"L") (pr \"R")) (S.yield (1,2)) -- in Sink.sink (Sink.unzip return (pr \"L") (pr \"R")) (S.fromPure (1,2))
-- L 1 -- L 1
-- R 2 -- R 2
-- @ -- @

View File

@ -786,7 +786,7 @@ apAhead (AheadT m1) (AheadT m2) =
instance (Monad m, MonadAsync m) => Applicative (AheadT m) where instance (Monad m, MonadAsync m) => Applicative (AheadT m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = AheadT . K.yield pure = AheadT . K.fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = apAhead (<*>) = apAhead

View File

@ -844,7 +844,7 @@ apAsync (AsyncT m1) (AsyncT m2) =
instance (Monad m, MonadAsync m) => Applicative (AsyncT m) where instance (Monad m, MonadAsync m) => Applicative (AsyncT m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = AsyncT . K.yield pure = AsyncT . K.fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = apAsync (<*>) = apAsync
@ -1143,7 +1143,7 @@ apWAsync (WAsyncT m1) (WAsyncT m2) =
-- GHC: if we specify arguments in the definition of (<*>) we see a significant -- GHC: if we specify arguments in the definition of (<*>) we see a significant
-- performance degradation (~2x). -- performance degradation (~2x).
instance (Monad m, MonadAsync m) => Applicative (WAsyncT m) where instance (Monad m, MonadAsync m) => Applicative (WAsyncT m) where
pure = WAsyncT . K.yield pure = WAsyncT . K.fromPure
(<*>) = apWAsync (<*>) = apWAsync
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View File

@ -14,7 +14,7 @@
module Streamly.Internal.Data.Stream.IsStream.Common module Streamly.Internal.Data.Stream.IsStream.Common
( (
-- * Generation -- * Generation
yield fromPure
, yieldM , yieldM
, repeatM , repeatM
, timesWith , timesWith
@ -44,6 +44,9 @@ module Streamly.Internal.Data.Stream.IsStream.Common
, concatMapM , concatMapM
, concatMap , concatMap
, splitOnSeq , splitOnSeq
-- * Deprecated
, yield
) )
where where
@ -92,7 +95,7 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
-- --
-- | -- |
-- @ -- @
-- yield a = a \`cons` nil -- fromPure a = a \`cons` nil
-- @ -- @
-- --
-- Create a singleton stream from a pure value. -- Create a singleton stream from a pure value.
@ -100,19 +103,20 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
-- The following holds in monadic streams, but not in Zip streams: -- The following holds in monadic streams, but not in Zip streams:
-- --
-- @ -- @
-- yield = pure -- fromPure = pure
-- yield = yieldM . pure -- fromPure = yieldM . pure
-- @ -- @
-- --
-- In Zip applicative streams 'yield' is not the same as 'pure' because in that -- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
-- case 'pure' is equivalent to 'repeat' instead. 'yield' and 'pure' are -- case 'pure' is equivalent to 'repeat' instead. 'fromPure' and 'pure' are
-- equally efficient, in other cases 'yield' may be slightly more efficient -- equally efficient, in other cases 'fromPure' may be slightly more efficient
-- than the other equivalent definitions. -- than the other equivalent definitions.
-- --
-- @since 0.4.0 -- /Since: 0.8.0 (Renamed yield to fromPure)/
{-# INLINE yield #-} --
yield :: IsStream t => a -> t m a {-# INLINE fromPure #-}
yield = K.yield fromPure :: IsStream t => a -> t m a
fromPure = K.fromPure
-- | -- |
-- @ -- @
@ -484,7 +488,7 @@ concatMap f m = fromStreamD $ D.concatMap (toStreamD . f) (toStreamD m)
-- --
{-# INLINE concatM #-} {-# INLINE concatM #-}
concatM :: (IsStream t, Monad m) => m (t m a) -> t m a concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
concatM generator = concatMapM (\() -> generator) (yield ()) concatM generator = concatMapM (\() -> generator) (fromPure ())
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Split stream and fold -- Split stream and fold
@ -545,3 +549,11 @@ splitOnSeq
:: (IsStream t, MonadIO m, Storable a, Enum a, Eq a) :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
=> Array a -> Fold m a b -> t m a -> t m b => Array a -> Fold m a b -> t m a -> t m b
splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m) splitOnSeq patt f m = D.fromStreamD $ D.splitOnSeq patt f (D.toStreamD m)
-- | Same as 'yield'
--
-- @since 0.4.0
{-# DEPRECATED yield "Please use fromPure instead." #-}
{-# INLINE yield #-}
yield :: IsStream t => a -> t m a
yield = fromPure

View File

@ -161,7 +161,7 @@ where
import Streamly.Internal.Data.Stream.Ahead (ahead) import Streamly.Internal.Data.Stream.Ahead (ahead)
import Streamly.Internal.Data.Stream.Async (async, wAsync) import Streamly.Internal.Data.Stream.Async (async, wAsync)
import Streamly.Internal.Data.Stream.IsStream.Common import Streamly.Internal.Data.Stream.IsStream.Common
(concatM, concatMapM, concatMap, smapM, yield, yieldM) (concatM, concatMapM, concatMap, smapM, fromPure, yieldM)
import Streamly.Internal.Data.Stream.Parallel (parallel) import Streamly.Internal.Data.Stream.Parallel (parallel)
import Streamly.Internal.Data.Stream.Prelude import Streamly.Internal.Data.Stream.Prelude
( concatFoldableWith, concatMapFoldableWith ( concatFoldableWith, concatMapFoldableWith
@ -685,7 +685,7 @@ concatMapEitherWith = undefined
-- --
-- For example, you can sort a stream using merge sort like this: -- For example, you can sort a stream using merge sort like this:
-- --
-- >>> Stream.toList $ Stream.concatPairsWith (Stream.mergeBy compare) Stream.yield $ Stream.fromList [5,1,7,9,2] -- >>> Stream.toList $ Stream.concatPairsWith (Stream.mergeBy compare) Stream.fromPure $ Stream.fromList [5,1,7,9,2]
-- [1,2,5,7,9] -- [1,2,5,7,9]
-- --
-- /Caution: the stream of streams must be finite/ -- /Caution: the stream of streams must be finite/
@ -723,7 +723,7 @@ concatPairsWith = K.concatPairsWith
-- @ -- @
-- Stream.iterateMapWith Stream.serial -- Stream.iterateMapWith Stream.serial
-- (either Dir.toEither (const nil)) -- (either Dir.toEither (const nil))
-- (yield (Left "tmp")) -- (fromPure (Left "tmp"))
-- @ -- @
-- --
-- /Pre-release/ -- /Pre-release/
@ -737,7 +737,7 @@ iterateMapWith
-> t m a -> t m a
iterateMapWith combine f = concatMapWith combine go iterateMapWith combine f = concatMapWith combine go
where where
go x = yield x `combine` concatMapWith combine go (f x) go x = fromPure x `combine` concatMapWith combine go (f x)
{- {-
{-# INLINE iterateUnfold #-} {-# INLINE iterateUnfold #-}
@ -778,7 +778,7 @@ iterateSmapMWith combine f initial stream =
where where
go b a = yield a `combine` feedback b a go b a = fromPure a `combine` feedback b a
feedback b a = feedback b a =
concatMap concatMap
@ -799,7 +799,7 @@ iterateSmapMWith combine f initial stream =
-- To traverse a directory tree: -- To traverse a directory tree:
-- --
-- @ -- @
-- iterateMapLeftsWith serial Dir.toEither (yield (Left "tmp")) -- iterateMapLeftsWith serial Dir.toEither (fromPure (Left "tmp"))
-- @ -- @
-- --
-- /Pre-release/ -- /Pre-release/

View File

@ -35,7 +35,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
, unfoldrM , unfoldrM
-- * From Values -- * From Values
, yield , fromPure
, yieldM , yieldM
, repeat , repeat
, repeatM , repeatM
@ -79,6 +79,7 @@ module Streamly.Internal.Data.Stream.IsStream.Generate
-- * Deprecated -- * Deprecated
, K.once , K.once
, yield
, each , each
, fromHandle , fromHandle
, currentTime , currentTime
@ -94,7 +95,8 @@ import Streamly.Internal.Data.SVar (MonadAsync, Rate (..))
import Streamly.Internal.Data.Stream.IsStream.Enumeration import Streamly.Internal.Data.Stream.IsStream.Enumeration
(Enumerable(..), enumerate, enumerateTo) (Enumerable(..), enumerate, enumerateTo)
import Streamly.Internal.Data.Stream.IsStream.Common import Streamly.Internal.Data.Stream.IsStream.Common
(absTimesWith, concatM, relTimesWith, timesWith, yield, yieldM, repeatM) ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, yield, yieldM
, repeatM)
import Streamly.Internal.Data.Stream.Prelude (fromStreamS) import Streamly.Internal.Data.Stream.Prelude (fromStreamS)
import Streamly.Internal.Data.Stream.StreamD (fromStreamD) import Streamly.Internal.Data.Stream.StreamD (fromStreamD)
import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM)) import Streamly.Internal.Data.Stream.StreamK (IsStream((|:), consM))

View File

@ -166,7 +166,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
, repeatM , repeatM
, scanlMAfter' , scanlMAfter'
, splitOnSeq , splitOnSeq
, yield) , fromPure)
import Streamly.Internal.Data.Stream.StreamK (IsStream) import Streamly.Internal.Data.Stream.StreamK (IsStream)
import Streamly.Internal.Data.Time.Units import Streamly.Internal.Data.Time.Units
( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime ( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
@ -573,11 +573,11 @@ groups = groupsBy (==)
-- --
-- splitOn is an inverse of intercalating single element: -- splitOn is an inverse of intercalating single element:
-- --
-- @Stream.intercalate (Stream.yield '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@ -- @Stream.intercalate (Stream.fromPure '.') Unfold.fromList . Stream.splitOn (== '.') Fold.toList === id@
-- --
-- Assuming the input stream does not contain the separator: -- Assuming the input stream does not contain the separator:
-- --
-- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.yield '.') Unfold.fromList === id@ -- @Stream.splitOn (== '.') Fold.toList . Stream.intercalate (Stream.fromPure '.') Unfold.fromList === id@
-- --
-- @since 0.7.0 -- @since 0.7.0
@ -639,11 +639,11 @@ splitOn predicate f =
-- --
-- 'splitOnSuffix' is an inverse of 'intercalateSuffix' with a single element: -- 'splitOnSuffix' is an inverse of 'intercalateSuffix' with a single element:
-- --
-- @Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@ -- @Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnSuffix (== '.') Fold.toList === id@
-- --
-- Assuming the input stream does not contain the separator: -- Assuming the input stream does not contain the separator:
-- --
-- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.yield '.') Unfold.fromList === id@ -- @Stream.splitOnSuffix (== '.') Fold.toList . Stream.intercalateSuffix (Stream.fromPure '.') Unfold.fromList === id@
-- --
-- @since 0.7.0 -- @since 0.7.0
@ -695,11 +695,11 @@ splitOnSuffix predicate f = foldMany (FL.takeEndBy_ predicate f)
-- --
-- 'splitOnPrefix' is an inverse of 'intercalatePrefix' with a single element: -- 'splitOnPrefix' is an inverse of 'intercalatePrefix' with a single element:
-- --
-- @Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@ -- @Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList . Stream.splitOnPrefix (== '.') Fold.toList === id@
-- --
-- Assuming the input stream does not contain the separator: -- Assuming the input stream does not contain the separator:
-- --
-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList === id@ -- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList === id@
-- --
-- /Unimplemented/ -- /Unimplemented/
@ -1268,7 +1268,7 @@ classifySessionsBy tick reset ejectPred tmout
, sessionEventTime = curTime , sessionEventTime = curTime
, sessionCount = cnt , sessionCount = cnt
, sessionKeyValueMap = mp , sessionKeyValueMap = mp
, sessionOutputStream = yield (key, fb) , sessionOutputStream = fromPure (key, fb)
} }
partial fs1 = do partial fs1 = do
let acc = Tuple' timestamp fs1 let acc = Tuple' timestamp fs1

View File

@ -192,7 +192,7 @@ sampleBurstStart gap =
{-# INLINE sortBy #-} {-# INLINE sortBy #-}
sortBy :: (IsStream t, Monad m) => (a -> a -> Ordering) -> t m a -> t m a sortBy :: (IsStream t, Monad m) => (a -> a -> Ordering) -> t m a -> t m a
-- XXX creating StreamD and using D.mergeBy may be more efficient due to fusion -- XXX creating StreamD and using D.mergeBy may be more efficient due to fusion
sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.yield sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.fromPure
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- SQL Joins -- SQL Joins
@ -339,7 +339,7 @@ leftJoin eq s1 s2 = Stream.evalStateT (return False) $ do
r <- lift get r <- lift get
if r if r
then StreamK.nil then StreamK.nil
else StreamK.yield Nothing else StreamK.fromPure Nothing
b <- fmap Just (Stream.liftInner s2) <> final b <- fmap Just (Stream.liftInner s2) <> final
case b of case b of
Just b1 -> Just b1 ->
@ -416,7 +416,7 @@ outerJoin eq s1 s =
r <- lift get r <- lift get
if r if r
then StreamK.nil then StreamK.nil
else StreamK.yield Nothing else StreamK.fromPure Nothing
(_i, b) <- (_i, b) <-
Stream.indexed Stream.indexed
$ fmap Just (Stream.liftInner (Array.toStream arr)) <> final $ fmap Just (Stream.liftInner (Array.toStream arr)) <> final

View File

@ -1092,7 +1092,7 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
-- @stream@ that is less than @elem@ when compared using @cmp@. -- @stream@ that is less than @elem@ when compared using @cmp@.
-- --
-- @ -- @
-- insertBy cmp x = 'mergeBy' cmp ('yield' x) -- insertBy cmp x = 'mergeBy' cmp ('fromPure' x)
-- @ -- @
-- --
-- @ -- @

View File

@ -554,7 +554,7 @@ apParallel (ParallelT m1) (ParallelT m2) =
instance (Monad m, MonadAsync m) => Applicative (ParallelT m) where instance (Monad m, MonadAsync m) => Applicative (ParallelT m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = ParallelT . K.yield pure = ParallelT . K.fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = apParallel (<*>) = apParallel

View File

@ -162,7 +162,7 @@ instance Monad m => Monad (SerialT m) where
-- Benchmarks better with StreamD bind and pure: -- Benchmarks better with StreamD bind and pure:
-- toList, filterAllout, *>, *<, >> (~2x) -- toList, filterAllout, *>, *<, >> (~2x)
-- --
-- pure = SerialT . D.fromStreamD . D.yield -- pure = SerialT . D.fromStreamD . D.fromPure
-- m >>= f = D.fromStreamD $ D.concatMap (D.toStreamD . f) (D.toStreamD m) -- m >>= f = D.fromStreamD $ D.concatMap (D.toStreamD . f) (D.toStreamD m)
-- Benchmarks better with CPS bind and pure: -- Benchmarks better with CPS bind and pure:
@ -219,7 +219,7 @@ apDiscardSnd (SerialT m1) (SerialT m2) =
-- INLINE them. -- INLINE them.
instance Monad m => Applicative (SerialT m) where instance Monad m => Applicative (SerialT m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = SerialT . K.yield pure = SerialT . K.fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = apSerial (<*>) = apSerial
@ -450,7 +450,7 @@ apWSerial (WSerialT m1) (WSerialT m2) =
instance Monad m => Applicative (WSerialT m) where instance Monad m => Applicative (WSerialT m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = WSerialT . K.yield pure = WSerialT . K.fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = apWSerial (<*>) = apWSerial

View File

@ -38,7 +38,7 @@ module Streamly.Internal.Data.Stream.StreamD.Generate
, unfoldrM , unfoldrM
-- * From Values -- * From Values
, yield , fromPure
, yieldM , yieldM
, repeat , repeat
, repeatM , repeatM

View File

@ -28,8 +28,8 @@ instance Functor (Step s) where
fmap _ Stop = Stop fmap _ Stop = Stop
{- {-
yield :: Monad m => a -> s -> m (Step s a) fromPure :: Monad m => a -> s -> m (Step s a)
yield a = return . Yield a fromPure a = return . Yield a
skip :: Monad m => s -> m (Step s a) skip :: Monad m => s -> m (Step s a)
skip = return . Skip skip = return . Skip

View File

@ -30,7 +30,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
, unfold , unfold
-- * From Values -- * From Values
, yield , fromPure
, yieldM , yieldM
-- * From Containers -- * From Containers
@ -188,9 +188,9 @@ unfold (Unfold ustep inject) seed = Stream step UnfoldNothing
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- | Create a singleton 'Stream' from a pure value. -- | Create a singleton 'Stream' from a pure value.
{-# INLINE_NORMAL yield #-} {-# INLINE_NORMAL fromPure #-}
yield :: Applicative m => a -> Stream m a fromPure :: Applicative m => a -> Stream m a
yield x = Stream (\_ s -> pure $ step undefined s) True fromPure x = Stream (\_ s -> pure $ step undefined s) True
where where
{-# INLINE_LATE step #-} {-# INLINE_LATE step #-}
step _ True = Yield x False step _ True = Yield x False
@ -673,7 +673,7 @@ apDiscardSnd (Stream stepa statea) (Stream stepb stateb) =
instance Applicative f => Applicative (Stream f) where instance Applicative f => Applicative (Stream f) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = yield pure = fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = concatAp (<*>) = concatAp
@ -728,7 +728,7 @@ unfoldMany (Unfold istep inject) (Stream ostep ost) =
Yield x i' -> Yield x (ConcatMapUInner o i') Yield x i' -> Yield x (ConcatMapUInner o i')
Skip i' -> Skip (ConcatMapUInner o i') Skip i' -> Skip (ConcatMapUInner o i')
Stop -> Skip (ConcatMapUOuter o) Stop -> Skip (ConcatMapUOuter o)
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Combine N Streams - concatMap -- Combine N Streams - concatMap
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ module Streamly.Internal.Data.Stream.StreamK
, iterateM , iterateM
-- ** Conversions -- ** Conversions
, yield , fromPure
, yieldM , yieldM
, fromFoldable , fromFoldable
, fromList , fromList
@ -272,7 +272,7 @@ once = yieldM
-- | -- |
-- @ -- @
-- repeatM = fix . cons -- repeatM = fix . cons
-- repeatM = cycle1 . yield -- repeatM = cycle1 . fromPure
-- @ -- @
-- --
-- Generate an infinite stream by repeating a monadic value. -- Generate an infinite stream by repeating a monadic value.
@ -929,7 +929,7 @@ intersperseM a m = prependingStart m
let yieldk i x = foldStreamShared st yld sng stp $ return i |: go x let yieldk i x = foldStreamShared st yld sng stp $ return i |: go x
in foldStream st yieldk sng stp m1 in foldStream st yieldk sng stp m1
go m2 = mkStream $ \st yld sng stp -> go m2 = mkStream $ \st yld sng stp ->
let single i = foldStreamShared st yld sng stp $ a |: yield i let single i = foldStreamShared st yld sng stp $ a |: fromPure i
yieldk i x = foldStreamShared st yld sng stp $ a |: return i |: go x yieldk i x = foldStreamShared st yld sng stp $ a |: return i |: go x
in foldStream st yieldk single stp m2 in foldStream st yieldk single stp m2
@ -943,8 +943,8 @@ insertBy cmp x m = go m
where where
go m1 = mkStream $ \st yld _ _ -> go m1 = mkStream $ \st yld _ _ ->
let single a = case cmp x a of let single a = case cmp x a of
GT -> yld a (yield x) GT -> yld a (fromPure x)
_ -> yld x (yield a) _ -> yld x (fromPure a)
stop = yld x nil stop = yld x nil
yieldk a r = case cmp x a of yieldk a r = case cmp x a of
GT -> yld a (go r) GT -> yld a (go r)

View File

@ -55,7 +55,7 @@ module Streamly.Internal.Data.Stream.StreamK.Type
, consMStream , consMStream
, consMBy , consMBy
, yieldM , yieldM
, yield , fromPure
, nil , nil
, nilM , nilM
@ -345,9 +345,9 @@ nil = mkStream $ \_ _ _ stp -> stp
nilM :: (IsStream t, Monad m) => m b -> t m a nilM :: (IsStream t, Monad m) => m b -> t m a
nilM m = mkStream $ \_ _ _ stp -> m >> stp nilM m = mkStream $ \_ _ _ stp -> m >> stp
{-# INLINE_NORMAL yield #-} {-# INLINE_NORMAL fromPure #-}
yield :: IsStream t => a -> t m a fromPure :: IsStream t => a -> t m a
yield a = mkStream $ \_ _ single _ -> single a fromPure a = mkStream $ \_ _ single _ -> single a
{-# INLINE_NORMAL yieldM #-} {-# INLINE_NORMAL yieldM #-}
yieldM :: (Monad m, IsStream t) => m a -> t m a yieldM :: (Monad m, IsStream t) => m a -> t m a
@ -487,7 +487,7 @@ foldrSShared = foldrSWith foldStreamShared
{-# RULES "foldrSShared/nil" {-# RULES "foldrSShared/nil"
forall k z. foldrSShared k z nil = z #-} forall k z. foldrSShared k z nil = z #-}
{-# RULES "foldrSShared/single" {-# RULES "foldrSShared/single"
forall k z x. foldrSShared k z (yield x) = k x z #-} forall k z x. foldrSShared k z (fromPure x) = k x z #-}
-- {-# RULES "foldrSShared/app" [1] -- {-# RULES "foldrSShared/app" [1]
-- forall ys. foldrSShared consM ys = \xs -> xs `conjoin` ys #-} -- forall ys. foldrSShared consM ys = \xs -> xs `conjoin` ys #-}
@ -501,7 +501,7 @@ foldrS = foldrSWith foldStream
-- See notes in GHC.Base about this rule -- See notes in GHC.Base about this rule
-- {-# RULES "foldr/cons" -- {-# RULES "foldr/cons"
-- forall k z x xs. foldrS k z (x `cons` xs) = k x (foldrS k z xs) #-} -- forall k z x xs. foldrS k z (x `cons` xs) = k x (foldrS k z xs) #-}
{-# RULES "foldrS/single" forall k z x. foldrS k z (yield x) = k x z #-} {-# RULES "foldrS/single" forall k z x. foldrS k z (fromPure x) = k x z #-}
-- {-# RULES "foldrS/app" [1] -- {-# RULES "foldrS/app" [1]
-- forall ys. foldrS cons ys = \xs -> xs `conjoin` ys #-} -- forall ys. foldrS cons ys = \xs -> xs `conjoin` ys #-}
@ -1173,7 +1173,7 @@ concatPairsWith combine f = go Nothing
instance Monad m => Applicative (Stream m) where instance Monad m => Applicative (Stream m) where
{-# INLINE pure #-} {-# INLINE pure #-}
pure = yield pure = fromPure
{-# INLINE (<*>) #-} {-# INLINE (<*>) #-}
(<*>) = ap (<*>) = ap

View File

@ -347,7 +347,7 @@ module Streamly.Prelude
-- ** From Values -- ** From Values
-- | Generate a monadic stream from a seed value or values. -- | Generate a monadic stream from a seed value or values.
, yield , fromPure
, yieldM , yieldM
, repeat , repeat
, repeatM , repeatM
@ -775,12 +775,12 @@ module Streamly.Prelude
-- One dimension loops are just a special case of nested loops. For -- One dimension loops are just a special case of nested loops. For
-- example, 'concatMap' can degenerate to a simple map operation: -- example, 'concatMap' can degenerate to a simple map operation:
-- --
-- > map f m = S.concatMap (\x -> S.yield (f x)) m -- > map f m = S.concatMap (\x -> S.fromPure (f x)) m
-- --
-- Similarly, 'concatMap' can perform filtering by mapping an element to a -- Similarly, 'concatMap' can perform filtering by mapping an element to a
-- 'nil' stream: -- 'nil' stream:
-- --
-- > filter p m = S.concatMap (\x -> if p x then S.yield x else S.nil) m -- > filter p m = S.concatMap (\x -> if p x then S.fromPure x else S.nil) m
-- --
, concatMapWith , concatMapWith
@ -920,6 +920,7 @@ module Streamly.Prelude
-- * Deprecated -- * Deprecated
, once , once
, yield
, each , each
, scanx , scanx
, foldx , foldx

View File

@ -24,7 +24,7 @@
-- used to fine tune the concurrency control. -- used to fine tune the concurrency control.
-- --
-- Streaming and concurrency together enable expressing reactive applications -- Streaming and concurrency together enable expressing reactive applications
-- conveniently. See the @CirclingSquare@ example in -- conveniently. See the @CirclingSquare@ example in
-- <https://github.com/composewell/streamly-examples Streamly Examples> for -- <https://github.com/composewell/streamly-examples Streamly Examples> for
-- a simple SDL based FRP example. To summarize, streamly provides a unified -- a simple SDL based FRP example. To summarize, streamly provides a unified
-- computing framework for streaming, non-determinism and functional reactive -- computing framework for streaming, non-determinism and functional reactive
@ -363,7 +363,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- ["hello","world"] -- ["hello","world"]
-- @ -- @
-- --
-- To create a singleton stream from a pure value use 'yield' or 'pure' and to -- To create a singleton stream from a pure value use 'fromPure' or 'pure' and to
-- create a singleton stream from a monadic action use 'yieldM'. Note that in -- create a singleton stream from a monadic action use 'yieldM'. Note that in
-- case of Zip applicative streams "pure" repeats the value to generate an -- case of Zip applicative streams "pure" repeats the value to generate an
-- infinite stream. -- infinite stream.
@ -371,7 +371,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- @ -- @
-- > S.'toList' $ 'pure' 1 -- > S.'toList' $ 'pure' 1
-- [1] -- [1]
-- > S.'toList' $ S.'yield' 1 -- > S.'toList' $ S.'fromPure' 1
-- [1] -- [1]
-- > S.'toList' $ S.'yieldM' 'getLine' -- > S.'toList' $ S.'yieldM' 'getLine'
-- hello -- hello
@ -1513,7 +1513,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- void $ runStateT runGame 60 -- void $ runStateT runGame 60
-- @ -- @
-- --
-- You can also find the source of this example in the streamly-examples repo -- You can also find the source of this example in the streamly-examples repo
-- as <https://github.com/composewell/streamly-examples/tree/master/AcidRain.hs AcidRain.hs>. -- as <https://github.com/composewell/streamly-examples/tree/master/AcidRain.hs AcidRain.hs>.
-- It has been adapted from Gabriel's -- It has been adapted from Gabriel's
-- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency> -- <https://hackage.haskell.org/package/pipes-concurrency-2.0.8/docs/Pipes-Concurrent-Tutorial.html pipes-concurrency>

View File

@ -558,7 +558,7 @@ main = hspec
serialOps $ prop "serially fromList" . constructWithFromList id serialOps $ prop "serially fromList" . constructWithFromList id
serialOps $ prop "serially fromListM" . constructWithFromListM id serialOps $ prop "serially fromListM" . constructWithFromListM id
serialOps $ prop "serially unfoldr" . constructWithUnfoldr id serialOps $ prop "serially unfoldr" . constructWithUnfoldr id
serialOps $ prop "serially yield" . constructWithYield id serialOps $ prop "serially fromPure" . constructWithYield id
serialOps $ prop "serially yieldM" . constructWithYieldM id serialOps $ prop "serially yieldM" . constructWithYieldM id
serialOps $ prop "serially cons" . constructWithCons S.cons serialOps $ prop "serially cons" . constructWithCons S.cons
serialOps $ prop "serially consM" . constructWithConsM S.consM id serialOps $ prop "serially consM" . constructWithConsM S.consM id

View File

@ -121,7 +121,7 @@ testLinesArray =
xs <- S.toList xs <- S.toList
$ S.map A.toList $ S.map A.toList
$ AS.splitOnSuffix 10 $ AS.splitOnSuffix 10
$ S.yield (A.fromList list) $ S.fromPure (A.fromList list)
assert (xs == map (map (fromIntegral . ord)) assert (xs == map (map (fromIntegral . ord))
(lines (map (chr . fromIntegral) list))) (lines (map (chr . fromIntegral) list)))

View File

@ -411,7 +411,7 @@ constructWithYield listT op len =
strm <- strm <-
run run
$ S.toList . op . S.take (fromIntegral len) $ S.toList . op . S.take (fromIntegral len)
$ foldMap S.yield (repeat 0) $ foldMap S.fromPure (repeat 0)
let list = replicate (fromIntegral len) 0 let list = replicate (fromIntegral len) 0
listEquals (==) (listT strm) list listEquals (==) (listT strm) list
@ -446,7 +446,7 @@ simpleProps constr op a = monadicIO $ do
simpleOps :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec simpleOps :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
simpleOps op = do simpleOps op = do
prop "yield a = a" $ simpleProps S.yield op prop "fromPure a = a" $ simpleProps S.fromPure op
prop "yieldM a = a" $ simpleProps (S.yieldM . return) op prop "yieldM a = a" $ simpleProps (S.yieldM . return) op
------------------------------------------------------------------------------- -------------------------------------------------------------------------------