@@ -57,7 +57,17 @@ module Streamly.Streams
5757 , (<=>) --deprecated
5858 , (<|) --deprecated
5959
60− -- * Stream Styles
60+ -- * IO Streams
61+ , Stream
62+ , Costream
63+ , Coparallel
64+ , Parallel
65+ , ZipStream
66+ , ZipParallel
67+ , fromIO
68+ , fromM
69+
70+ -- * Stream Transformers
6171 , StreamT
6272 , CostreamT
6373 , InterleavedT -- deprecated
@@ -111,7 +121,7 @@ import Control.Monad.State.Class (MonadState(..))
111121import Control.Monad.Trans.Class (MonadTrans (lift))
112122import Data.Semigroup (Semigroup(..))
113123import Prelude hiding (zipWith)
114−import Streamly.Core ( MonadParallel, Stream(Stream)
124+import Streamly.Core ( MonadParallel
115125 , singleton
116126 , SVar, SVarStyle(..)
117127 , SVarTag(..), SVarSched(..))
@@ -124,8 +134,8 @@ import qualified Streamly.Core as S
124134-- | Class of types that can represent a stream of elements of some type 'a' in
125135-- some monad 'm'.
126136class IsStream t where
127− toStream :: t m a -> Stream m a
128− fromStream :: Stream m a -> t m a
137+ toStream :: t m a -> S.Stream m a
138+ fromStream :: S.Stream m a -> t m a
129139
130140-- | Same as 'IsStream'.
131141{-# Deprecated Streaming "Please use IsStream instead." #-}
@@ -195,13 +205,13 @@ streamBuild :: IsStream t
195205 -> m r
196206 -> m r)
197207 -> t m a
198−streamBuild k = fromStream $ Stream $ \svr stp sng yld ->
208+streamBuild k = fromStream $ S.Stream $ \svr stp sng yld ->
199209 let yield a r = yld a (toStream r)
200210 in k svr yield sng stp
201211
202212-- | Build a singleton stream from a callback function.
203213fromCallback :: IsStream t => (forall r. (a -> m r) -> m r) -> t m a
204−fromCallback k = fromStream $ Stream $ \_ _ sng _ -> k sng
214+fromCallback k = fromStream $ S.Stream $ \_ _ sng _ -> k sng
205215
206216-- | Read an SVar to get a stream.
207217fromSVar :: (MonadParallel m, IsStream t) => SVar m a -> t m a
@@ -358,7 +368,7 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
358368-- Note that serial composition can be used to combine an infinite number of
359369-- streams as it explores only one stream at a time.
360370--
361−newtype StreamT m a = StreamT {getStreamT :: Stream m a}
371+newtype StreamT m a = StreamT {getStreamT :: S.Stream m a}
362372 deriving (Semigroup, Monoid, Functor, MonadTrans)
363373
364374instance IsStream StreamT where
@@ -382,7 +392,7 @@ splice m1 m2 = fromStream $ S.splice (toStream m1) (toStream m2)
382392
383393instance Monad m => Monad (StreamT m) where
384394 return = pure
385− (StreamT (Stream m)) >>= f = StreamT $ Stream $ \_ stp sng yld ->
395+ (StreamT (S.Stream m)) >>= f = StreamT $ S.Stream $ \_ stp sng yld ->
386396 let run x = (S.runStream x) Nothing stp sng yld
387397 single a = run $ toStream (f a)
388398 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
@@ -429,7 +439,7 @@ MONAD_COMMON_INSTANCES(StreamT,)
429439-- Note that interleaving composition can only combine a finite number of
430440-- streams as it needs to retain state for each unfinished stream.
431441--
432−newtype CostreamT m a = CostreamT {getCostreamT :: Stream m a}
442+newtype CostreamT m a = CostreamT {getCostreamT :: S.Stream m a}
433443 deriving (Functor, MonadTrans)
434444
435445{-# DEPRECATED InterleavedT "Please use 'CostreamT' instead." #-}
@@ -474,7 +484,7 @@ instance Monoid (CostreamT m a) where
474484
475485instance Monad m => Monad (CostreamT m) where
476486 return = pure
477− (CostreamT (Stream m)) >>= f = CostreamT $ Stream $ \_ stp sng yld ->
487+ (CostreamT (S.Stream m)) >>= f = CostreamT $ S.Stream $ \_ stp sng yld ->
478488 let run x = (S.runStream x) Nothing stp sng yld
479489 single a = run $ toStream (f a)
480490 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
@@ -530,7 +540,7 @@ MONAD_COMMON_INSTANCES(CostreamT,)
530540-- Note that this composition can be used to combine infinite number of streams
531541-- as it explores only a bounded number of streams at a time.
532542--
533−newtype CoparallelT m a = CoparallelT {getCoparallelT :: Stream m a}
543+newtype CoparallelT m a = CoparallelT {getCoparallelT :: S.Stream m a}
534544 deriving (Functor, MonadTrans)
535545
536546{-# DEPRECATED AsyncT "Please use 'CoparallelT' instead." #-}
@@ -574,14 +584,14 @@ instance MonadParallel m => Monoid (CoparallelT m a) where
574584
575585{-# INLINE parbind #-}
576586parbind
577− :: (forall c. Stream m c -> Stream m c -> Stream m c)
578− -> Stream m a
579− -> (a -> Stream m b)
580− -> Stream m b
587+ :: (forall c. S.Stream m c -> S.Stream m c -> S.Stream m c)
588+ -> S.Stream m a
589+ -> (a -> S.Stream m b)
590+ -> S.Stream m b
581591parbind par m f = go m
582592 where
583− go (Stream g) =
584− Stream $ \ctx stp sng yld ->
593+ go (S.Stream g) =
594+ S.Stream $ \ctx stp sng yld ->
585595 let run x = (S.runStream x) ctx stp sng yld
586596 single a = run $ f a
587597 yield a r = run $ f a `par` go r
@@ -640,7 +650,7 @@ MONAD_COMMON_INSTANCES(CoparallelT, MONADPARALLEL)
640650-- Note that round robin composition can only combine a finite number of
641651-- streams as it needs to retain state for each unfinished stream.
642652--
643−newtype ParallelT m a = ParallelT {getParallelT :: Stream m a}
653+newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
644654 deriving (Functor, MonadTrans)
645655
646656instance IsStream ParallelT where
@@ -692,7 +702,7 @@ MONAD_COMMON_INSTANCES(ParallelT, MONADPARALLEL)
692702zipWith :: IsStream t => (a -> b -> c) -> t m a -> t m b -> t m c
693703zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
694704 where
695− go mx my = Stream $ \_ stp sng yld -> do
705+ go mx my = S.Stream $ \_ stp sng yld -> do
696706 let merge a ra =
697707 let single2 b = sng (f a b)
698708 yield2 b rb = yld (f a b) (go ra rb)
@@ -718,7 +728,7 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
718728-- The 'Semigroup' instance of this type works the same way as that of
719729-- 'StreamT'.
720730--
721−newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: Stream m a}
731+newtype ZipStreamM m a = ZipStreamM {getZipStreamM :: S.Stream m a}
722732 deriving (Functor, Semigroup, Monoid)
723733
724734instance Monad m => Applicative (ZipStreamM m) where
@@ -737,7 +747,7 @@ instance IsStream ZipStreamM where
737747-- generated concurrently) using a pure zipping function.
738748zipParallelWith :: (IsStream t, MonadParallel m)
739749 => (a -> b -> c) -> t m a -> t m b -> t m c
740−zipParallelWith f m1 m2 = fromStream $ Stream $ \_ stp sng yld -> do
750+zipParallelWith f m1 m2 = fromStream $ S.Stream $ \_ stp sng yld -> do
741751 ma <- async m1
742752 mb <- async m2
743753 (S.runStream (toStream (zipWith f ma mb))) Nothing stp sng yld
@@ -763,7 +773,7 @@ zipAsyncWith = zipParallelWith
763773-- The 'Semigroup' instance of this type works the same way as that of
764774-- 'StreamT'.
765775--
766−newtype ZipParallelM m a = ZipParallelM {getZipParallelM :: Stream m a}
776+newtype ZipParallelM m a = ZipParallelM {getZipParallelM :: S.Stream m a}
767777 deriving (Functor, Semigroup, Monoid)
768778
769779{-# DEPRECATED ZipAsync "Please use ZipParallelM instead." #-}
@@ -863,6 +873,41 @@ runZipStream = runStream . zipStreamly
863873runZipAsync :: Monad m => ZipParallelM m a -> m ()
864874runZipAsync = runStream . zipParallely
865875
876+------------------------------------------------------------------------------
877+-- IO Streams
878+------------------------------------------------------------------------------
879+
880+-- | A serial IO stream of elements of type @a@. See 'StreamT' documentation
881+-- for more details.
882+type Stream a = StreamT IO a
883+
884+-- | An interleaving serial IO stream of elements of type @a@. See 'CostreamT'
885+-- documentation for more details.
886+type Costream a = CostreamT IO a
887+
888+-- | A demand driven left biased parallelly composing IO stream of elements of
889+-- type @a@. See 'CoparallelT' documentation for more details.
890+type Coparallel a = CoparallelT IO a
891+
892+-- | A round robin parallelly composing IO stream of elements of type @a@.
893+-- See 'ParallelT' documentation for more details.
894+type Parallel a = ParallelT IO a
895+
896+-- | An IO stream whose applicative instance zips streams serially.
897+type ZipStream a = ZipStreamM IO a
898+
899+-- | An IO stream whose applicative instance zips streams parallely.
900+type ZipParallel a = ZipParallelM IO a
901+
902+-- | Lift a value from IO monad to any of the stream types. This works for all
903+-- stream types including those that are not monads e.g. 'ZipStream' and
904+-- 'ZipParallel'.
905+fromIO :: (IsStream t, MonadIO m) => IO a -> t m a
906+fromIO = streamly . liftIO
907+
908+fromM :: (IsStream t, Monad m) => m a -> t m a
909+fromM = streamly . lift
910+
866911------------------------------------------------------------------------------
867912-- Fold Utilities
868913------------------------------------------------------------------------------