on master help sign in
Add before, concatEffect, concatMapEffect to StreamK
57b9276Harendra Kumar
core/src/Streamly/Internal/Data/Stream/StreamK/Type.hs+28
@@ -89,6 +89,10 @@ module Streamly.Internal.Data.Stream.StreamK.Type
89 , foldlS
89 , foldlS
90 , reverse
90 , reverse
91
91
92+ , before
93+ , concatEffect
94+ , concatMapEffect
95+
92 -- * Interleave
96 -- * Interleave
93 , interleave
97 , interleave
94 , interleaveFst
98 , interleaveFst
@@ -1375,6 +1379,30 @@ foldlS step = go
1375reverse :: Stream m a -> Stream m a
1379reverse :: Stream m a -> Stream m a
1376reverse = foldlS (flip cons) nil
1380reverse = foldlS (flip cons) nil
1377
1381
1382+------------------------------------------------------------------------------
1383+-- Runnining effects
1384+------------------------------------------------------------------------------
1385+
1386+-- | Run an action before evaluating the stream.
1387+{-# INLINE before #-}
1388+before :: Monad m => m b -> Stream m a -> Stream m a
1389+before action stream =
1390+ mkStream $ \st yld sng stp ->
1391+ action >> foldStreamShared st yld sng stp stream
1392+
1393+-- | concat . fromEffect
1394+{-# INLINE concatEffect #-}
1395+concatEffect :: Monad m => m (Stream m a) -> Stream m a
1396+concatEffect action =
1397+ mkStream $ \st yld sng stp ->
1398+ action >>= foldStreamShared st yld sng stp
1399+
1400+{-# INLINE concatMapEffect #-}
1401+concatMapEffect :: Monad m => (b -> Stream m a) -> m b -> Stream m a
1402+concatMapEffect f action =
1403+ mkStream $ \st yld sng stp ->
1404+ action >>= foldStreamShared st yld sng stp . f
1405+
1378------------------------------------------------------------------------------
1406------------------------------------------------------------------------------
1379-- Lifting inner monad
1407-- Lifting inner monad
1380------------------------------------------------------------------------------
1408------------------------------------------------------------------------------