@@ -31,9 +31,7 @@ module Streamly.Streams
3131
3232 -- * Construction
3333 , nil
34− , cons
3534 , (.:)
36− , consM
3735 , (|:)
3836 , streamBuild
3937 , fromCallback
@@ -134,6 +132,8 @@ import qualified Streamly.Core as S
134132class IsStream t where
135133 toStream :: t m a -> S.Stream m a
136134 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
137137
138138-- | Same as 'IsStream'.
139139--
@@ -169,8 +169,9 @@ infixr 5 `consM`
169169-- @
170170--
171171-- @since 0.2.0
172−consM :: (IsStream t, Monad m) => m a -> t m a -> t m a
173−consM m r = fromStream $ S.consM m (toStream r)
172+-- {-# INLINE consMSerial #-}
173+consMSerial :: (IsStream t, Monad m) => m a -> t m a -> t m a
174+consMSerial m r = fromStream $ S.consM m (toStream r)
174175
175176infixr 5 |:
176177
@@ -198,8 +199,8 @@ infixr 5 `cons`
198199-- @
199200--
200201-- @since 0.1.0
201−cons :: IsStream t => a -> t m a -> t m a
202−cons a r = fromStream $ S.cons a (toStream r)
202+consSerial :: IsStream t => a -> t m a -> t m a
203+consSerial a r = fromStream $ S.cons a (toStream r)
203204
204205infixr 5 .:
205206
@@ -411,6 +412,10 @@ type StreamT = SerialT
411412instance IsStream SerialT where
412413 toStream = getSerialT
413414 fromStream = SerialT
415+ cons = consSerial
416+ {-# INLINE consM #-}
417+ {-# SPECIALIZE consM :: IO a -> SerialT IO a -> SerialT IO a #-}
418+ consM = consMSerial
414419
415420------------------------------------------------------------------------------
416421-- Semigroup
@@ -496,6 +501,10 @@ type InterleavedT = WSerialT
496501instance IsStream WSerialT where
497502 toStream = getWSerialT
498503 fromStream = WSerialT
504+ cons = consSerial
505+ {-# INLINE consM #-}
506+ {-# SPECIALIZE consM :: IO a -> WSerialT IO a -> WSerialT IO a #-}
507+ consM = consMSerial
499508
500509------------------------------------------------------------------------------
501510-- Semigroup
@@ -603,6 +612,10 @@ newtype AheadT m a = AheadT {getAheadT :: S.Stream m a}
603612instance IsStream AheadT where
604613 toStream = getAheadT
605614 fromStream = AheadT
615+ cons = consSerial
616+ {-# INLINE consM #-}
617+ {-# SPECIALIZE consM :: IO a -> AheadT IO a -> AheadT IO a #-}
618+ consM = consMSerial
606619
607620------------------------------------------------------------------------------
608621-- Semigroup
@@ -716,6 +729,10 @@ newtype AsyncT m a = AsyncT {getAsyncT :: S.Stream m a}
716729instance IsStream AsyncT where
717730 toStream = getAsyncT
718731 fromStream = AsyncT
732+ cons = consSerial
733+ {-# INLINE consM #-}
734+ {-# SPECIALIZE consM :: IO a -> AsyncT IO a -> AsyncT IO a #-}
735+ consM = consMSerial
719736
720737------------------------------------------------------------------------------
721738-- Semigroup
@@ -836,6 +853,10 @@ newtype WAsyncT m a = WAsyncT {getWAsyncT :: S.Stream m a}
836853instance IsStream WAsyncT where
837854 toStream = getWAsyncT
838855 fromStream = WAsyncT
856+ cons = consSerial
857+ {-# INLINE consM #-}
858+ {-# SPECIALIZE consM :: IO a -> WAsyncT IO a -> WAsyncT IO a #-}
859+ consM = consMSerial
839860
840861------------------------------------------------------------------------------
841862-- Semigroup
@@ -971,6 +992,10 @@ newtype ParallelT m a = ParallelT {getParallelT :: S.Stream m a}
971992instance IsStream ParallelT where
972993 toStream = getParallelT
973994 fromStream = ParallelT
995+ cons = consSerial
996+ {-# INLINE consM #-}
997+ {-# SPECIALIZE consM :: IO a -> ParallelT IO a -> ParallelT IO a #-}
998+ consM = consMSerial
974999
9751000------------------------------------------------------------------------------
9761001-- Semigroup
@@ -1043,6 +1068,10 @@ type ZipStream = ZipSerialM
10431068instance IsStream ZipSerialM where
10441069 toStream = getZipSerialM
10451070 fromStream = ZipSerialM
1071+ cons = consSerial
1072+ {-# INLINE consM #-}
1073+ {-# SPECIALIZE consM :: IO a -> ZipSerialM IO a -> ZipSerialM IO a #-}
1074+ consM = consMSerial
10461075
10471076instance Monad m => Applicative (ZipSerialM m) where
10481077 pure = ZipSerialM . S.repeat
@@ -1075,6 +1104,10 @@ newtype ZipAsyncM m a = ZipAsyncM {getZipAsyncM :: S.Stream m a}
10751104instance IsStream ZipAsyncM where
10761105 toStream = getZipAsyncM
10771106 fromStream = ZipAsyncM
1107+ cons = consSerial
1108+ {-# INLINE consM #-}
1109+ {-# SPECIALIZE consM :: IO a -> ZipAsyncM IO a -> ZipAsyncM IO a #-}
1110+ consM = consMSerial
10781111
10791112instance MonadAsync m => Applicative (ZipAsyncM m) where
10801113 pure = ZipAsyncM . S.repeat