@@ -73,6 +73,15 @@ import Prelude hiding (map, repeat, zipWith, errorWithoutStackTrace)
7373
7474#include "Instances.hs"
7575
76+-- $setup
77+-- >>> import Control.Concurrent (threadDelay)
78+-- >>> :{
79+-- delay n = do
80+-- threadDelay (n * 1000000) -- sleep for n seconds
81+-- putStrLn (show n ++ " sec") -- print "n sec"
82+-- return n -- IO Int
83+-- :}
84+
7685-- | Like 'zipWith' but using a monadic zipping function.
7786--
7887-- @since 0.4.0
@@ -120,9 +129,14 @@ zipAsyncWith f = zipAsyncWithM (\a b -> return (f a b))
120129-- Serially Zipping Streams
121130------------------------------------------------------------------------------
122131
123−-- | The applicative instance of 'ZipSerialM' zips a number of streams serially
124−-- i.e. it produces one element from each stream serially and then zips all
125−-- those elements.
132+-- | For 'ZipSerialM' streams:
133+--
134+-- @
135+-- (<>) = 'Streamly.Prelude.serial'
136+-- (<*>) = 'Streamly.Prelude.serial.zipWith' id
137+-- @
138+--
139+-- Applicative evaluates the streams being zipped serially:
126140--
127141-- >>> s1 = Stream.fromFoldable [1, 2]
128142-- >>> s2 = Stream.fromFoldable [3, 4]
@@ -130,9 +144,6 @@ zipAsyncWith f = zipAsyncWithM (\a b -> return (f a b))
130144-- >>> Stream.toList $ Stream.zipSerially $ (,,) <$> s1 <*> s2 <*> s3
131145-- [(1,3,5),(2,4,6)]
132146--
133−-- The 'Semigroup' instance of this type works the same way as that of
134−-- 'SerialT'.
135−--
136147-- /Since: 0.2.0 ("Streamly")/
137148--
138149-- @since 0.8.0
@@ -202,21 +213,20 @@ TRAVERSABLE_INSTANCE(ZipSerialM)
202213-- Parallely Zipping Streams
203214------------------------------------------------------------------------------
204215--
205−-- | Like 'ZipSerialM' but zips in parallel, it generates all the elements to
206−-- be zipped concurrently.
216+-- | For 'ZipAsyncM' streams:
207217--
208218-- @
209−-- main = (toList . 'zipAsyncly' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
210−-- where s1 = fromFoldable [1, 2]
211−-- s2 = fromFoldable [3, 4]
212−-- s3 = fromFoldable [5, 6]
213−-- @
214−-- @
215−-- [(1,3,5),(2,4,6)]
219+-- (<>) = 'Streamly.Prelude.serial'
220+-- (<*>) = 'Streamly.Prelude.serial.zipAsyncWith' id
216221-- @
217222--
218−-- The 'Semigroup' instance of this type works the same way as that of
219−-- 'SerialT'.
223+-- Applicative evaluates the streams being zipped concurrently, the following
224+-- would take half the time that it would take in serial zipping:
225+--
226+-- >>> s = Stream.fromFoldableM $ Prelude.map delay [1, 1, 1]
227+-- >>> Stream.toList $ Stream.zipAsyncly $ (,) <$> s <*> s
228+-- ...
229+-- [(1,1),(1,1),(1,1)]
220230--
221231-- /Since: 0.2.0 ("Streamly")/
222232--