@@ -71,6 +71,7 @@ import Control.DeepSeq (NFData)
71import Control.Exception (try)
71import Control.Exception (try)
72import GHC.Exception (ErrorCall)
72import GHC.Exception (ErrorCall)
73import Streamly.Internal.Data.Stream (Stream)
73import Streamly.Internal.Data.Stream (Stream)
74+import Streamly.Internal.Data.Stream.Cross (CrossStream(..))
74import System.Random (randomRIO)
75import System.Random (randomRIO)
76import qualified Streamly.Internal.Data.Fold as Fold
77import qualified Streamly.Internal.Data.Fold as Fold
@@ -227,9 +228,9 @@ sourceConcatMapId value n =
227{-# INLINE apDiscardFst #-}
228{-# INLINE apDiscardFst #-}
228apDiscardFst :: MonadAsync m =>
229apDiscardFst :: MonadAsync m =>
229 Int -> Int -> m ()
230 Int -> Int -> m ()
230−apDiscardFst linearCount start = drain $
231+apDiscardFst linearCount start = drain $ getCrossStream $
231− sourceUnfoldrM nestedCount2 start
232+ CrossStream (sourceUnfoldrM nestedCount2 start)
232− *> sourceUnfoldrM nestedCount2 start
233+ *> CrossStream (sourceUnfoldrM nestedCount2 start)
@@ -237,9 +238,9 @@ apDiscardFst linearCount start = drain $
238{-# INLINE apDiscardSnd #-}
239{-# INLINE apDiscardSnd #-}
239apDiscardSnd :: MonadAsync m => Int -> Int -> m ()
240apDiscardSnd :: MonadAsync m => Int -> Int -> m ()
240−apDiscardSnd linearCount start = drain $
241+apDiscardSnd linearCount start = drain $ getCrossStream $
241− sourceUnfoldrM nestedCount2 start
242+ CrossStream (sourceUnfoldrM nestedCount2 start)
242− <* sourceUnfoldrM nestedCount2 start
243+ <* CrossStream (sourceUnfoldrM nestedCount2 start)
@@ -247,9 +248,9 @@ apDiscardSnd linearCount start = drain $
248{-# INLINE apLiftA2 #-}
249{-# INLINE apLiftA2 #-}
249apLiftA2 :: MonadAsync m => Int -> Int -> m ()
250apLiftA2 :: MonadAsync m => Int -> Int -> m ()
250−apLiftA2 linearCount start = drain $
251+apLiftA2 linearCount start = drain $ getCrossStream $
251− liftA2 (+) (sourceUnfoldrM nestedCount2 start)
252+ liftA2 (+) (CrossStream (sourceUnfoldrM nestedCount2 start))
252− (sourceUnfoldrM nestedCount2 start)
253+ (CrossStream (sourceUnfoldrM nestedCount2 start))
@@ -257,9 +258,9 @@ apLiftA2 linearCount start = drain $
258{-# INLINE toNullAp #-}
259{-# INLINE toNullAp #-}
259toNullAp :: MonadAsync m => Int -> Int -> m ()
260toNullAp :: MonadAsync m => Int -> Int -> m ()
260−toNullAp linearCount start = drain $
261+toNullAp linearCount start = drain $ getCrossStream $
261− (+) <$> sourceUnfoldrM nestedCount2 start
262+ (+) <$> CrossStream (sourceUnfoldrM nestedCount2 start)
262− <*> sourceUnfoldrM nestedCount2 start
263+ <*> CrossStream (sourceUnfoldrM nestedCount2 start)
@@ -267,9 +268,9 @@ toNullAp linearCount start = drain $
268{-# INLINE monadThen #-}
269{-# INLINE monadThen #-}
269monadThen :: MonadAsync m => Int -> Int -> m ()
270monadThen :: MonadAsync m => Int -> Int -> m ()
270−monadThen linearCount start = drain $ do
271+monadThen linearCount start = drain $ getCrossStream $ do
271− sourceUnfoldrM nestedCount2 start >>
272+ CrossStream (sourceUnfoldrM nestedCount2 start) >>
272− sourceUnfoldrM nestedCount2 start
273+ CrossStream (sourceUnfoldrM nestedCount2 start)
@@ -277,9 +278,9 @@ monadThen linearCount start = drain $ do
278{-# INLINE toNullM #-}
279{-# INLINE toNullM #-}
279toNullM :: MonadAsync m => Int -> Int -> m ()
280toNullM :: MonadAsync m => Int -> Int -> m ()
280−toNullM linearCount start = drain $ do
281+toNullM linearCount start = drain $ getCrossStream $ do
281− x <- sourceUnfoldrM nestedCount2 start
282+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
282− y <- sourceUnfoldrM nestedCount2 start
283+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
283 return $ x + y
284 return $ x + y
@@ -288,56 +289,56 @@ toNullM linearCount start = drain $ do
289{-# INLINE toNullM3 #-}
290{-# INLINE toNullM3 #-}
290toNullM3 :: MonadAsync m => Int -> Int -> m ()
291toNullM3 :: MonadAsync m => Int -> Int -> m ()
291−toNullM3 linearCount start = drain $ do
292+toNullM3 linearCount start = drain $ getCrossStream $ do
292− x <- sourceUnfoldrM nestedCount3 start
293+ x <- CrossStream (sourceUnfoldrM nestedCount3 start)
293− y <- sourceUnfoldrM nestedCount3 start
294+ y <- CrossStream (sourceUnfoldrM nestedCount3 start)
294− z <- sourceUnfoldrM nestedCount3 start
295+ z <- CrossStream (sourceUnfoldrM nestedCount3 start)
295 return $ x + y + z
296 return $ x + y + z
297 nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
298 nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
299{-# INLINE filterAllOutM #-}
300{-# INLINE filterAllOutM #-}
300filterAllOutM :: MonadAsync m => Int -> Int -> m ()
301filterAllOutM :: MonadAsync m => Int -> Int -> m ()
301−filterAllOutM linearCount start = drain $ do
302+filterAllOutM linearCount start = drain $ getCrossStream $ do
302− x <- sourceUnfoldrM nestedCount2 start
303+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
303− y <- sourceUnfoldrM nestedCount2 start
304+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
304 let s = x + y
305 let s = x + y
306 then return s
307 then return s
307− else Stream.nil
308+ else CrossStream Stream.nil
309 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
310 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
311{-# INLINE filterAllInM #-}
312{-# INLINE filterAllInM #-}
312filterAllInM :: MonadAsync m => Int -> Int -> m ()
313filterAllInM :: MonadAsync m => Int -> Int -> m ()
313−filterAllInM linearCount start = drain $ do
314+filterAllInM linearCount start = drain $ getCrossStream $ do
314− x <- sourceUnfoldrM nestedCount2 start
315+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
315− y <- sourceUnfoldrM nestedCount2 start
316+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
316 let s = x + y
317 let s = x + y
318 then return s
319 then return s
319− else Stream.nil
320+ else CrossStream Stream.nil
321 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
322 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
323{-# INLINE filterSome #-}
324{-# INLINE filterSome #-}
324filterSome :: MonadAsync m => Int -> Int -> m ()
325filterSome :: MonadAsync m => Int -> Int -> m ()
325−filterSome linearCount start = drain $ do
326+filterSome linearCount start = drain $ getCrossStream $ do
326− x <- sourceUnfoldrM nestedCount2 start
327+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
327− y <- sourceUnfoldrM nestedCount2 start
328+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
328 let s = x + y
329 let s = x + y
329 if s > 1100000
330 if s > 1100000
330 then return s
331 then return s
331− else Stream.nil
332+ else CrossStream Stream.nil
333 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
334 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
335{-# INLINE breakAfterSome #-}
336{-# INLINE breakAfterSome #-}
336breakAfterSome :: Int -> Int -> IO ()
337breakAfterSome :: Int -> Int -> IO ()
337breakAfterSome linearCount start = do
338breakAfterSome linearCount start = do
338− (_ :: Either ErrorCall ()) <- try $ drain $ do
339+ (_ :: Either ErrorCall ()) <- try $ drain $ getCrossStream $ do
339− x <- sourceUnfoldrM nestedCount2 start
340+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
340− y <- sourceUnfoldrM nestedCount2 start
341+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
341 let s = x + y
342 let s = x + y
342 if s > 1100000
343 if s > 1100000
343 then error "break"
344 then error "break"
@@ -348,9 +349,9 @@ breakAfterSome linearCount start = do
349{-# INLINE toListM #-}
350{-# INLINE toListM #-}
350toListM :: MonadAsync m => Int -> Int -> m [Int]
351toListM :: MonadAsync m => Int -> Int -> m [Int]
351−toListM linearCount start = Stream.fold Fold.toList $ do
352+toListM linearCount start = Stream.fold Fold.toList $ getCrossStream $ do
352− x <- sourceUnfoldrM nestedCount2 start
353+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
353− y <- sourceUnfoldrM nestedCount2 start
354+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
354 return $ x + y
355 return $ x + y
356 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
357 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
@@ -360,9 +361,9 @@ toListM linearCount start = Stream.fold Fold.toList $ do
360{-# INLINE toListSome #-}
361{-# INLINE toListSome #-}
361toListSome :: MonadAsync m => Int -> Int -> m [Int]
362toListSome :: MonadAsync m => Int -> Int -> m [Int]
362toListSome linearCount start =
363toListSome linearCount start =
363− Stream.fold Fold.toList $ Stream.take 10000 $ do
364+ Stream.fold Fold.toList $ Stream.take 10000 $ getCrossStream $ do
364− x <- sourceUnfoldrM nestedCount2 start
365+ x <- CrossStream (sourceUnfoldrM nestedCount2 start)
365− y <- sourceUnfoldrM nestedCount2 start
366+ y <- CrossStream (sourceUnfoldrM nestedCount2 start)
366 return $ x + y
367 return $ x + y
368 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
369 nestedCount2 = round (fromIntegral linearCount**(1/2::Double))