@@ -62,6 +62,7 @@ module Streamly.Internal.Data.Unfold
63 -- * Operations on Input
63 -- * Operations on Input
66 , supplyFirst
67 , supplyFirst
67 , supplySecond
68 , supplySecond
@@ -94,6 +95,7 @@ module Streamly.Internal.Data.Unfold
95 -- * Transformations
96 -- * Transformations
98 -- * Filtering
100 -- * Filtering
99 , takeWhileM
101 , takeWhileM
@@ -121,7 +123,7 @@ where
121import Control.Exception (Exception)
123import Control.Exception (Exception)
122import Data.Void (Void)
124import Data.Void (Void)
123import GHC.Types (SPEC(..))
125import GHC.Types (SPEC(..))
124−import Prelude hiding (concat, map, takeWhile, take, filter, const)
126+import Prelude hiding (concat, map, mapM, takeWhile, take, filter, const)
126import Streamly.Internal.Data.Stream.StreamD.Type (Stream(..), Step(..))
128import Streamly.Internal.Data.Stream.StreamD.Type (Stream(..), Step(..))
127#if __GLASGOW_HASKELL__ < 800
129#if __GLASGOW_HASKELL__ < 800
@@ -149,6 +151,13 @@ import qualified Streamly.Streams.StreamD as D
149lmap :: (a -> c) -> Unfold m c b -> Unfold m a b
151lmap :: (a -> c) -> Unfold m c b -> Unfold m a b
150lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
152lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
154+-- | Map an action on the input argument of the 'Unfold'.
157+{-# INLINE_NORMAL lmapM #-}
158+lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b
159+lmapM f (Unfold ustep uinject) = Unfold ustep (\x -> f x >>= uinject)
152-- | Supply the seed to an unfold closing the input end of the unfold.
161-- | Supply the seed to an unfold closing the input end of the unfold.
154-- /Internal/
163-- /Internal/
@@ -244,6 +253,18 @@ map f (Unfold ustep uinject) = Unfold step uinject
244 Skip s -> Skip s
253 Skip s -> Skip s
245 Stop -> Stop
254 Stop -> Stop
256+{-# INLINE_NORMAL mapM #-}
257+mapM :: Monad m => (b -> m c) -> Unfold m a b -> Unfold m a c
258+mapM f (Unfold ustep uinject) = Unfold step uinject
260+ {-# INLINE_LATE step #-}
264+ Yield x s -> f x >>= \a -> return $ Yield a s
265+ Skip s -> return $ Skip s
266+ Stop -> return $ Stop
247-------------------------------------------------------------------------------
268-------------------------------------------------------------------------------
248-- Convert streams into unfolds
269-- Convert streams into unfolds
249-------------------------------------------------------------------------------
270-------------------------------------------------------------------------------