@@ -31,9 +31,7 @@ module Streamly.Streams
32 -- * Construction
32 -- * Construction
38 , streamBuild
36 , streamBuild
39 , fromCallback
37 , fromCallback
@@ -134,6 +132,8 @@ import qualified Streamly.Core as S
134class IsStream t where
132class IsStream t where
135 toStream :: t m a -> S.Stream m a
133 toStream :: t m a -> S.Stream m a
136 fromStream :: S.Stream m a -> t m a
134 fromStream :: S.Stream m a -> t m a
135+ cons :: a -> t m a -> t m a
136+ consM :: Monad m => m a -> t m a -> t m a
138-- | Same as 'IsStream'.
138-- | Same as 'IsStream'.
@@ -169,8 +169,9 @@ infixr 5 `consM`
171-- @since 0.2.0
171-- @since 0.2.0
172+-- {-# INLINE consMSerial #-}
172−consM :: (IsStream t, Monad m) => m a -> t m a -> t m a
173+consMSerial :: (IsStream t, Monad m) => m a -> t m a -> t m a
173−consM m r = fromStream $ S.consM m (toStream r)
174+consMSerial m r = fromStream $ S.consM m (toStream r)
175infixr 5 |:
176infixr 5 |:
@@ -198,8 +199,8 @@ infixr 5 `cons`
200-- @since 0.1.0
201-- @since 0.1.0
201−cons :: IsStream t => a -> t m a -> t m a
202+consSerial :: IsStream t => a -> t m a -> t m a
202−cons a r = fromStream $ S.cons a (toStream r)
203+consSerial a r = fromStream $ S.cons a (toStream r)
204infixr 5 .:
205infixr 5 .:
@@ -411,6 +412,10 @@ type StreamT = SerialT
411instance IsStream SerialT where
412instance IsStream SerialT where
412 toStream = getSerialT
413 toStream = getSerialT
413 fromStream = SerialT
414 fromStream = SerialT
416+ {-# INLINE consM #-}
417+ {-# SPECIALIZE consM :: IO a -> SerialT IO a -> SerialT IO a #-}
415------------------------------------------------------------------------------
420------------------------------------------------------------------------------
416-- Semigroup
421-- Semigroup
@@ -496,6 +501,10 @@ type InterleavedT = WSerialT
496instance IsStream WSerialT where
501instance IsStream WSerialT where
497 toStream = getWSerialT
502 toStream = getWSerialT
498 fromStream = WSerialT
503 fromStream = WSerialT
505+ {-# INLINE consM #-}
506+ {-# SPECIALIZE consM :: IO a -> WSerialT IO a -> WSerialT IO a #-}
500------------------------------------------------------------------------------
509------------------------------------------------------------------------------
501-- Semigroup
510-- Semigroup
@@ -603,6 +612,10 @@ newtype AheadT m a = AheadT {getAheadT :: S.Stream m a}
603instance IsStream AheadT where
612instance IsStream AheadT where
604 toStream = getAheadT
613 toStream = getAheadT
605 fromStream = AheadT
614 fromStream = AheadT
616+ {-# INLINE consM #-}
617+ {-# SPECIALIZE consM :: IO a -> AheadT IO a -> AheadT IO a #-}
607------------------------------------------------------------------------------
620------------------------------------------------------------------------------
608-- Semigroup
621-- Semigroup
@@ -716,6 +729,10 @@ newtype AsyncT m a = AsyncT {getAsyncT :: S.Stream m a}
716instance IsStream AsyncT where
729instance IsStream AsyncT where
717 toStream = getAsyncT
730 toStream = getAsyncT
718 fromStream = AsyncT
731 fromStream = AsyncT
733+ {-# INLINE consM #-}
734+ {-# SPECIALIZE consM :: IO a -> AsyncT IO a -> AsyncT IO a #-}
720------------------------------------------------------------------------------
737------------------------------------------------------------------------------
721-- Semigroup
738-- Semigroup
@@ -836,6 +853,10 @@ newtype WAsyncT m a = WAsyncT {getWAsyncT :: S.Stream m a}
836instance IsStream WAsyncT where
853instance IsStream WAsyncT where
837 toStream = getWAsyncT
854 toStream = getWAsyncT
838 fromStream = WAsyncT
855 fromStream = WAsyncT
857+ {-# INLINE consM #-}
858+ {-# SPECIALIZE consM :: IO a -> WAsyncT IO a -> WAsyncT IO a #-}
840------------------------------------------------------------------------------
861------------------------------------------------------------------------------
841-- Semigroup
862-- Semigroup
@@ -971,6 +992,10 @@ newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
971instance IsStream ParallelT where
992instance IsStream ParallelT where
972 toStream = getParallelT
993 toStream = getParallelT
973 fromStream = ParallelT
994 fromStream = ParallelT
996+ {-# INLINE consM #-}
997+ {-# SPECIALIZE consM :: IO a -> ParallelT IO a -> ParallelT IO a #-}
975------------------------------------------------------------------------------
1000------------------------------------------------------------------------------
976-- Semigroup
1001-- Semigroup
@@ -1043,6 +1068,10 @@ type ZipStream = ZipSerialM
1043instance IsStream ZipSerialM where
1068instance IsStream ZipSerialM where
1044 toStream = getZipSerialM
1069 toStream = getZipSerialM
1045 fromStream = ZipSerialM
1070 fromStream = ZipSerialM
1072+ {-# INLINE consM #-}
1073+ {-# SPECIALIZE consM :: IO a -> ZipSerialM IO a -> ZipSerialM IO a #-}
1074+ consM = consMSerial
1047instance Monad m => Applicative (ZipSerialM m) where
1076instance Monad m => Applicative (ZipSerialM m) where
1048 pure = ZipSerialM . S.repeat
1077 pure = ZipSerialM . S.repeat
@@ -1075,6 +1104,10 @@ newtype ZipAsyncM m a = ZipAsyncM {getZipAsyncM :: S.Stream m a}
1075instance IsStream ZipAsyncM where
1104instance IsStream ZipAsyncM where
1076 toStream = getZipAsyncM
1105 toStream = getZipAsyncM
1077 fromStream = ZipAsyncM
1106 fromStream = ZipAsyncM
1108+ {-# INLINE consM #-}
1109+ {-# SPECIALIZE consM :: IO a -> ZipAsyncM IO a -> ZipAsyncM IO a #-}
1110+ consM = consMSerial
1079instance MonadAsync m => Applicative (ZipAsyncM m) where
1112instance MonadAsync m => Applicative (ZipAsyncM m) where
1080 pure = ZipAsyncM . S.repeat
1113 pure = ZipAsyncM . S.repeat