on master help sign in
Add before, concatEffect, concatMapEffect to StreamK
commit57b9276f9f85d9582b319a5772d6bfc03b211d31 authorHarendra Kumar <harendra@composewell.com> dateSun 18 Sep 2022, 09:39 (4 years ago) parent0780dbb
1 file changed+28
core/src/Streamly/Internal/Data/Stream/StreamK/Type.hs+28
core/src/Streamly/Internal/Data/Stream/StreamK/Type.hs+28
@@ -89,6 +89,10 @@ module Streamly.Internal.Data.Stream.StreamK.Type
8989 , foldlS
9090 , reverse
9191
92+ , before
93+ , concatEffect
94+ , concatMapEffect
95+
9296 -- * Interleave
9397 , interleave
9498 , interleaveFst
@@ -1375,6 +1379,30 @@ foldlS step = go
13751379reverse :: Stream m a -> Stream m a
13761380reverse = foldlS (flip cons) nil
13771381
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+
13781406------------------------------------------------------------------------------
13791407-- Lifting inner monad
13801408------------------------------------------------------------------------------