@@ -151,7 +151,7 @@ module Streamly.Streams.StreamK
153 -- * Utilities
153 -- * Utilities
154− , consMSerial
154+ , consMStream
155 , bindWith
155 , bindWith
156 , withLocal
156 , withLocal
@@ -197,6 +197,7 @@ infixr 5 `cons`
199-- @since 0.1.0
199-- @since 0.1.0
200cons :: IsStream t => a -> t m a -> t m a
201cons :: IsStream t => a -> t m a -> t m a
201cons a r = mkStream $ \_ yld _ _ -> yld a r
202cons a r = mkStream $ \_ yld _ _ -> yld a r
@@ -210,6 +211,7 @@ infixr 5 .:
212-- @since 0.1.1
213-- @since 0.1.1
213(.:) :: IsStream t => a -> t m a -> t m a
215(.:) :: IsStream t => a -> t m a -> t m a
214(.:) = cons
216(.:) = cons
@@ -269,6 +271,7 @@ unfoldrM step = go
269-- Special generation
271-- Special generation
270-------------------------------------------------------------------------------
272-------------------------------------------------------------------------------
272yield :: IsStream t => a -> t m a
275yield :: IsStream t => a -> t m a
273yield a = mkStream $ \_ _ single _ -> single a
276yield a = mkStream $ \_ _ single _ -> single a
@@ -289,14 +292,17 @@ once = yieldM
289-- Generate an infinite stream by repeating a pure value.
292-- Generate an infinite stream by repeating a pure value.
291-- @since 0.4.0
294-- @since 0.4.0
295+{-# INLINE repeat #-}
292repeat :: IsStream t => a -> t m a
296repeat :: IsStream t => a -> t m a
293repeat a = let x = cons a x in x
297repeat a = let x = cons a x in x
299+{-# INLINE replicateM #-}
295replicateM :: (IsStream t, MonadAsync m) => Int -> m a -> t m a
300replicateM :: (IsStream t, MonadAsync m) => Int -> m a -> t m a
296replicateM n m = go n
301replicateM n m = go n
298 go cnt = if cnt <= 0 then nil else m |: go (cnt - 1)
303 go cnt = if cnt <= 0 then nil else m |: go (cnt - 1)
305+{-# INLINE replicate #-}
300replicate :: IsStream t => Int -> a -> t m a
306replicate :: IsStream t => Int -> a -> t m a
301replicate n a = go n
307replicate n a = go n
@@ -331,6 +337,7 @@ fromStreamK = fromStream
331-------------------------------------------------------------------------------
337-------------------------------------------------------------------------------
333-- | Lazy right associative fold.
339-- | Lazy right associative fold.
334foldr :: (IsStream t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
341foldr :: (IsStream t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
335foldr step acc m = go m
342foldr step acc m = go m
@@ -405,6 +412,7 @@ foldl' step begin = foldx step begin id
406-- XXX replace the recursive "go" with explicit continuations.
413-- XXX replace the recursive "go" with explicit continuations.
407-- | Like 'foldx', but with a monadic step function.
414-- | Like 'foldx', but with a monadic step function.
415+{-# INLINABLE foldxM #-}
408foldxM :: (IsStream t, Monad m)
416foldxM :: (IsStream t, Monad m)
409 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
417 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
410foldxM step begin done m = go begin m
418foldxM step begin done m = go begin m
@@ -416,6 +424,7 @@ foldxM step begin done m = go begin m
416 in foldStream defState yieldk single stop m1
424 in foldStream defState yieldk single stop m1
418-- | Like 'foldl'' but with a monadic step function.
426-- | Like 'foldl'' but with a monadic step function.
427+{-# INLINE foldlM' #-}
419foldlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> m b
428foldlM' :: (IsStream t, Monad m) => (b -> a -> m b) -> b -> t m a -> m b
420foldlM' step begin = foldxM step (return begin) return
429foldlM' step begin = foldxM step (return begin) return
@@ -494,6 +503,7 @@ notElem e m = go m
494 yieldk a r = if a == e then return False else go r
503 yieldk a r = if a == e then return False else go r
495 in foldStream defState yieldk single stop m1
504 in foldStream defState yieldk single stop m1
506+{-# INLINABLE all #-}
497all :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
507all :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
498all p m = go m
508all p m = go m
@@ -504,6 +514,7 @@ all p m = go m
504 | otherwise = return False
514 | otherwise = return False
505 in foldStream defState yieldk single (return True) m1
515 in foldStream defState yieldk single (return True) m1
517+{-# INLINABLE any #-}
507any :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
518any :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> m Bool
508any p m = go m
519any p m = go m
@@ -741,6 +752,7 @@ takeWhile p m = go m
741 | otherwise = stp
752 | otherwise = stp
742 in foldStream st yieldk single stp m1
753 in foldStream st yieldk single stp m1
744drop :: IsStream t => Int -> t m a -> t m a
756drop :: IsStream t => Int -> t m a -> t m a
745drop n m = go n m
757drop n m = go n m
@@ -874,6 +886,7 @@ zipWith f = go
874-- | Zip two streams serially using a monadic zipping function.
886-- | Zip two streams serially using a monadic zipping function.
876-- @since 0.1.0
888-- @since 0.1.0
889+{-# INLINABLE zipWithM #-}
877zipWithM :: (IsStream t, Monad m) => (a -> b -> m c) -> t m a -> t m b -> t m c
890zipWithM :: (IsStream t, Monad m) => (a -> b -> m c) -> t m a -> t m b -> t m c
878zipWithM f m1 m2 = go m1 m2
891zipWithM f m1 m2 = go m1 m2
@@ -974,6 +987,7 @@ _alt m1 m2 = mkStream $ \st yld sng stp ->
974-- MonadReader
987-- MonadReader
975------------------------------------------------------------------------------
988------------------------------------------------------------------------------
990+{-# INLINABLE withLocal #-}
977withLocal :: MonadReader r m => (r -> r) -> Stream m a -> Stream m a
991withLocal :: MonadReader r m => (r -> r) -> Stream m a -> Stream m a
978withLocal f m =
992withLocal f m =
979 mkStream $ \st yld sng stp ->
993 mkStream $ \st yld sng stp ->