@@ -105,6 +105,10 @@ module Streamly.Internal.Data.Unfold
106 , filterM
106 , filterM
108 -- * Nesting
112 -- * Nesting
110 , concatMapM
114 , concatMapM
@@ -130,7 +134,8 @@ import Control.Monad.IO.Class (MonadIO(..))
130import Control.Monad.Trans.Control (MonadBaseControl)
134import Control.Monad.Trans.Control (MonadBaseControl)
131import Data.Void (Void)
135import Data.Void (Void)
132import GHC.Types (SPEC(..))
136import GHC.Types (SPEC(..))
133−import Prelude hiding (concat, map, mapM, takeWhile, take, filter, const)
138+ hiding (concat, map, mapM, takeWhile, take, filter, const, zipWith)
135import Streamly.Internal.Data.Stream.StreamD.Type (Stream(..), Step(..))
140import Streamly.Internal.Data.Stream.StreamD.Type (Stream(..), Step(..))
136#if __GLASGOW_HASKELL__ < 800
141#if __GLASGOW_HASKELL__ < 800
@@ -520,6 +525,45 @@ enumerateFromToIntegral to =
520enumerateFromIntegral :: (Monad m, Integral a, Bounded a) => Unfold m a a
525enumerateFromIntegral :: (Monad m, Integral a, Bounded a) => Unfold m a a
521enumerateFromIntegral = enumerateFromToIntegral maxBound
526enumerateFromIntegral = enumerateFromToIntegral maxBound
528+-------------------------------------------------------------------------------
530+-------------------------------------------------------------------------------
532+{-# INLINE_NORMAL zipWithM #-}
534+ => (a -> b -> m c) -> Unfold m x a -> Unfold m y b -> Unfold m (x, y) c
535+zipWithM f (Unfold step1 inject1) (Unfold step2 inject2) = Unfold step inject
542+ return (s1, s2, Nothing)
544+ {-# INLINE_LATE step #-}
545+ step (s1, s2, Nothing) = do
549+ Yield x s -> Skip (s, s2, Just x)
550+ Skip s -> Skip (s, s2, Nothing)
553+ step (s1, s2, Just x) = do
558+ return $ Yield z (s1, s, Nothing)
559+ Skip s -> return $ Skip (s1, s, Just x)
562+{-# INLINE zipWith #-}
564+ => (a -> b -> c) -> Unfold m x a -> Unfold m y b -> Unfold m (x, y) c
565+zipWith f = zipWithM (\a b -> return (f a b))
523-------------------------------------------------------------------------------
567-------------------------------------------------------------------------------
525-------------------------------------------------------------------------------
569-------------------------------------------------------------------------------