@@ -54,8 +54,8 @@ import Prelude hiding (const, map, concatMap, zipWith)
5454-- $setup
5555-- >>> :m
5656-- >>> import qualified Streamly.Prelude as Stream
57−-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
58−-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold
57+-- >>> import qualified Streamly.Data.Fold as Fold
58+-- >>> import qualified Streamly.Data.Unfold as Unfold
5959
6060------------------------------------------------------------------------------
6161-- Monadic Unfolds
@@ -125,7 +125,7 @@ yieldM m = Unfold step inject
125125
126126-- | Discards the unfold input and always returns the argument of 'yield'.
127127yield :: Applicative m => b -> Unfold m a b
128−yield = yieldM . pure
128+yield = yieldM Prelude.. pure
129129
130130-- | Outer product discarding the first element.
131131--
@@ -218,7 +218,7 @@ apply u1 u2 = fmap (\(a, b) -> a b) (cross u1 u2)
218218--
219219instance Monad m => Applicative (Unfold m a) where
220220 {-# INLINE pure #-}
221− pure = const Prelude.. return
221+ pure = yield
222222
223223 {-# INLINE (<*>) #-}
224224 (<*>) = apply
@@ -314,8 +314,6 @@ instance Monad m => Monad (Unfold m a) where
314314-- Category
315315-------------------------------------------------------------------------------
316316
317−-- XXX change it to yieldM or change yieldM in Prelude to singletonM
318−--
319317-- | Lift a monadic function into an unfold generating a singleton stream.
320318--
321319{-# INLINE singletonM #-}
@@ -397,20 +395,25 @@ instance Monad m => Category (Unfold m) where
397395-}
398396
399397-------------------------------------------------------------------------------
400−-- Arrow
398+-- Zipping
401399-------------------------------------------------------------------------------
402400
403−-- | Stops as soon as any of the unfolds stops.
401+-- | Distribute the input to two unfolds and then zip the outputs to a single
402+-- stream using a monadic zip function.
403+--
404+-- Stops as soon as any of the unfolds stops.
405+--
406+-- /Pre-release/
404407{-# INLINE_NORMAL zipWithM #-}
405408zipWithM :: Monad m
406− => (a -> b -> m c) -> Unfold m x a -> Unfold m y b -> Unfold m (x, y) c
409+ => (b -> c -> m d) -> Unfold m a b -> Unfold m a c -> Unfold m a d
407410zipWithM f (Unfold step1 inject1) (Unfold step2 inject2) = Unfold step inject
408411
409412 where
410413
411− inject (x, y) = do
414+ inject x = do
412415 s1 <- inject1 x
413− s2 <- inject2 y
416+ s2 <- inject2 x
414417 return (s1, s2, Nothing)
415418
416419 {-# INLINE_LATE step #-}
@@ -431,23 +434,27 @@ zipWithM f (Unfold step1 inject1) (Unfold step2 inject2) = Unfold step inject
431434 Skip s -> return $ Skip (s1, s, Just x)
432435 Stop -> return Stop
433436
434−-- | Divide the input into two unfolds and then zip the outputs to a single
435−-- stream.
437+-- | Like 'zipWithM' but with a pure zip function.
436438--
437−-- @
438−-- S.mapM_ print
439−-- $ S.unfoldMany (UF.zipWith (,) UF.identity (UF.singleton sqrt))
440−-- $ S.map (\x -> (x,x))
441−-- $ S.fromList [1..10]
442−-- @
439+-- >>> square = fmap (\x -> x * x) Unfold.fromList
440+-- >>> cube = fmap (\x -> x * x * x) Unfold.fromList
441+-- >>> u = Unfold.zipWith (,) square cube
442+-- >>> Unfold.fold u Fold.toList [1..5]
443+-- [(1,1),(4,8),(9,27),(16,64),(25,125)]
444+--
445+-- > zipWith f = zipWithM (\a b -> return $ f a b)
443446--
444447-- /Pre-release/
445448--
446449{-# INLINE zipWith #-}
447450zipWith :: Monad m
448− => (a -> b -> c) -> Unfold m x a -> Unfold m y b -> Unfold m (x, y) c
451+ => (b -> c -> d) -> Unfold m a b -> Unfold m a c -> Unfold m a d
449452zipWith f = zipWithM (\a b -> return (f a b))
450453
454+-------------------------------------------------------------------------------
455+-- Arrow
456+-------------------------------------------------------------------------------
457+
451458{-
452459-- XXX There are multiple ways of combining the outputs of two unfolds, we
453460-- could zip, merge, append and more. What is the preferred way for Arrow
@@ -464,5 +471,5 @@ instance Monad m => Arrow (Unfold m) where
464471 arr = singleton
465472
466473 {-# INLINE (***) #-}
467− (***) = zipWith (,)
474+ u1 *** u2 = zipWith (,) (lmap fst u1) (lmap snd u2)
468475-}