on master help sign in
Add teeZipWith

This could be useful to distribute the input two unfolds, transform each part using a different transformation and then merge the ouputs in a single stream.

commite799043bc6501a32aa92150da36ace3b0e9761cd authorHarendra Kumar <harendra@composewell.com> dateTue 25 Feb 2020, 02:36 (7 years ago) parenteccf24a
1 file changed+11
src/Streamly/Internal/Data/Unfold.hs+11
src/Streamly/Internal/Data/Unfold.hs+11
@@ -109,6 +109,7 @@ module Streamly.Internal.Data.Unfold
109109 -- * Zipping
110110 , zipWithM
111111 , zipWith
112+ , teeZipWith
112113
113114 -- * Nesting
114115 , concat
@@ -590,6 +591,16 @@ zipWith :: Monad m
590591 => (a -> b -> c) -> Unfold m x a -> Unfold m y b -> Unfold m (x, y) c
591592zipWith f = zipWithM (\a b -> return (f a b))
592593
594+-- | Distribute the input to two unfolds and then zip the outputs to a single
595+-- stream.
596+--
597+-- /Internal/
598+--
599+{-# INLINE_NORMAL teeZipWith #-}
600+teeZipWith :: Monad m
601+ => (a -> b -> c) -> Unfold m x a -> Unfold m x b -> Unfold m x c
602+teeZipWith f unf1 unf2 = lmap (\x -> (x,x)) $ zipWith f unf1 unf2
603+
593604-------------------------------------------------------------------------------
594605-- Nested
595606-------------------------------------------------------------------------------