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`
* `forEachWith` to `concatForFoldableWith`
* `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:
* `encodeUtf8Lax` to `encodeUtf8`
* `encodeLatin1Lax` to `encodeLatin1`

View File

@ -89,7 +89,7 @@ drainWhile value = IP.parse (PR.drainWhile (<= value))
{-# INLINE sliceBeginWith #-}
sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
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
IP.parse (PR.sliceBeginWith (== value) FL.drain) stream2

View File

@ -71,7 +71,7 @@ drainWhile p = PR.takeWhile p FL.drain
{-# INLINE sliceBeginWith #-}
sliceBeginWith :: MonadCatch m => Int -> SerialT m Int -> m ()
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
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 #-}
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 #-}
sourceFoldMapWithM :: Monad m => Int -> Stream m Int

View File

@ -154,7 +154,7 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) S.nil
{-# INLINE concatMapFoldableSerial #-}
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 #-}
concatMapFoldableSerialM :: Monad m => Int -> Int -> Stream m Int

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@
module Streamly.Internal.Data.Stream.IsStream.Common
(
-- * Generation
yield
fromPure
, yieldM
, repeatM
, timesWith
@ -44,6 +44,9 @@ module Streamly.Internal.Data.Stream.IsStream.Common
, concatMapM
, concatMap
, splitOnSeq
-- * Deprecated
, yield
)
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.
@ -100,19 +103,20 @@ import Prelude hiding (take, takeWhile, drop, reverse, concatMap)
-- The following holds in monadic streams, but not in Zip streams:
--
-- @
-- yield = pure
-- yield = yieldM . pure
-- fromPure = pure
-- fromPure = yieldM . pure
-- @
--
-- In Zip applicative streams 'yield' is not the same as 'pure' because in that
-- case 'pure' is equivalent to 'repeat' instead. 'yield' and 'pure' are
-- equally efficient, in other cases 'yield' may be slightly more efficient
-- In Zip applicative streams 'fromPure' is not the same as 'pure' because in that
-- case 'pure' is equivalent to 'repeat' instead. 'fromPure' and 'pure' are
-- equally efficient, in other cases 'fromPure' may be slightly more efficient
-- than the other equivalent definitions.
--
-- @since 0.4.0
{-# INLINE yield #-}
yield :: IsStream t => a -> t m a
yield = K.yield
-- /Since: 0.8.0 (Renamed yield to fromPure)/
--
{-# INLINE fromPure #-}
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 #-}
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
@ -545,3 +549,11 @@ splitOnSeq
:: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
=> 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)
-- | 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.Async (async, wAsync)
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.Prelude
( concatFoldableWith, concatMapFoldableWith
@ -685,7 +685,7 @@ concatMapEitherWith = undefined
--
-- 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]
--
-- /Caution: the stream of streams must be finite/
@ -723,7 +723,7 @@ concatPairsWith = K.concatPairsWith
-- @
-- Stream.iterateMapWith Stream.serial
-- (either Dir.toEither (const nil))
-- (yield (Left "tmp"))
-- (fromPure (Left "tmp"))
-- @
--
-- /Pre-release/
@ -737,7 +737,7 @@ iterateMapWith
-> t m a
iterateMapWith combine f = concatMapWith combine go
where
go x = yield x `combine` concatMapWith combine go (f x)
go x = fromPure x `combine` concatMapWith combine go (f x)
{-
{-# INLINE iterateUnfold #-}
@ -778,7 +778,7 @@ iterateSmapMWith combine f initial stream =
where
go b a = yield a `combine` feedback b a
go b a = fromPure a `combine` feedback b a
feedback b a =
concatMap
@ -799,7 +799,7 @@ iterateSmapMWith combine f initial stream =
-- To traverse a directory tree:
--
-- @
-- iterateMapLeftsWith serial Dir.toEither (yield (Left "tmp"))
-- iterateMapLeftsWith serial Dir.toEither (fromPure (Left "tmp"))
-- @
--
-- /Pre-release/

View File

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

View File

@ -166,7 +166,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
, repeatM
, scanlMAfter'
, splitOnSeq
, yield)
, fromPure)
import Streamly.Internal.Data.Stream.StreamK (IsStream)
import Streamly.Internal.Data.Time.Units
( AbsTime, MilliSecond64(..), addToAbsTime, toRelTime
@ -573,11 +573,11 @@ groups = groupsBy (==)
--
-- 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:
--
-- @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
@ -639,11 +639,11 @@ splitOn predicate f =
--
-- '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:
--
-- @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
@ -695,11 +695,11 @@ splitOnSuffix predicate f = foldMany (FL.takeEndBy_ predicate f)
--
-- '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:
--
-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.yield '.') Unfold.fromList === id@
-- @Stream.splitOnPrefix (== '.') Fold.toList . Stream.intercalatePrefix (Stream.fromPure '.') Unfold.fromList === id@
--
-- /Unimplemented/
@ -1268,7 +1268,7 @@ classifySessionsBy tick reset ejectPred tmout
, sessionEventTime = curTime
, sessionCount = cnt
, sessionKeyValueMap = mp
, sessionOutputStream = yield (key, fb)
, sessionOutputStream = fromPure (key, fb)
}
partial fs1 = do
let acc = Tuple' timestamp fs1

View File

@ -192,7 +192,7 @@ sampleBurstStart gap =
{-# INLINE sortBy #-}
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
sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.yield
sortBy f = Stream.concatPairsWith (Stream.mergeBy f) Stream.fromPure
------------------------------------------------------------------------------
-- SQL Joins
@ -339,7 +339,7 @@ leftJoin eq s1 s2 = Stream.evalStateT (return False) $ do
r <- lift get
if r
then StreamK.nil
else StreamK.yield Nothing
else StreamK.fromPure Nothing
b <- fmap Just (Stream.liftInner s2) <> final
case b of
Just b1 ->
@ -416,7 +416,7 @@ outerJoin eq s1 s =
r <- lift get
if r
then StreamK.nil
else StreamK.yield Nothing
else StreamK.fromPure Nothing
(_i, b) <-
Stream.indexed
$ 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@.
--
-- @
-- 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
{-# INLINE pure #-}
pure = ParallelT . K.yield
pure = ParallelT . K.fromPure
{-# INLINE (<*>) #-}
(<*>) = apParallel

View File

@ -162,7 +162,7 @@ instance Monad m => Monad (SerialT m) where
-- Benchmarks better with StreamD bind and pure:
-- 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)
-- Benchmarks better with CPS bind and pure:
@ -219,7 +219,7 @@ apDiscardSnd (SerialT m1) (SerialT m2) =
-- INLINE them.
instance Monad m => Applicative (SerialT m) where
{-# INLINE pure #-}
pure = SerialT . K.yield
pure = SerialT . K.fromPure
{-# INLINE (<*>) #-}
(<*>) = apSerial
@ -450,7 +450,7 @@ apWSerial (WSerialT m1) (WSerialT m2) =
instance Monad m => Applicative (WSerialT m) where
{-# INLINE pure #-}
pure = WSerialT . K.yield
pure = WSerialT . K.fromPure
{-# INLINE (<*>) #-}
(<*>) = apWSerial

View File

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

View File

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

View File

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

View File

@ -61,7 +61,7 @@ module Streamly.Internal.Data.Stream.StreamK
, iterateM
-- ** Conversions
, yield
, fromPure
, yieldM
, fromFoldable
, fromList
@ -272,7 +272,7 @@ once = yieldM
-- |
-- @
-- repeatM = fix . cons
-- repeatM = cycle1 . yield
-- repeatM = cycle1 . fromPure
-- @
--
-- 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
in foldStream st yieldk sng stp m1
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
in foldStream st yieldk single stp m2
@ -943,8 +943,8 @@ insertBy cmp x m = go m
where
go m1 = mkStream $ \st yld _ _ ->
let single a = case cmp x a of
GT -> yld a (yield x)
_ -> yld x (yield a)
GT -> yld a (fromPure x)
_ -> yld x (fromPure a)
stop = yld x nil
yieldk a r = case cmp x a of
GT -> yld a (go r)

View File

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

View File

@ -347,7 +347,7 @@ module Streamly.Prelude
-- ** From Values
-- | Generate a monadic stream from a seed value or values.
, yield
, fromPure
, yieldM
, repeat
, repeatM
@ -775,12 +775,12 @@ module Streamly.Prelude
-- One dimension loops are just a special case of nested loops. For
-- 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
-- '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
@ -920,6 +920,7 @@ module Streamly.Prelude
-- * Deprecated
, once
, yield
, each
, scanx
, foldx

View File

@ -24,7 +24,7 @@
-- used to fine tune the concurrency control.
--
-- 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
-- a simple SDL based FRP example. To summarize, streamly provides a unified
-- computing framework for streaming, non-determinism and functional reactive
@ -363,7 +363,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- ["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
-- case of Zip applicative streams "pure" repeats the value to generate an
-- infinite stream.
@ -371,7 +371,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- @
-- > S.'toList' $ 'pure' 1
-- [1]
-- > S.'toList' $ S.'yield' 1
-- > S.'toList' $ S.'fromPure' 1
-- [1]
-- > S.'toList' $ S.'yieldM' 'getLine'
-- hello
@ -1513,7 +1513,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
-- 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>.
-- It has been adapted from Gabriel's
-- <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 fromListM" . constructWithFromListM 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 cons" . constructWithCons S.cons
serialOps $ prop "serially consM" . constructWithConsM S.consM id

View File

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

View File

@ -411,7 +411,7 @@ constructWithYield listT op len =
strm <-
run
$ S.toList . op . S.take (fromIntegral len)
$ foldMap S.yield (repeat 0)
$ foldMap S.fromPure (repeat 0)
let list = replicate (fromIntegral len) 0
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 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
-------------------------------------------------------------------------------