@@ -1,78 +0,0 @@
1−#if !(MIN_VERSION_base(4,11,0))
2−import Data.Semigroup ((<>))
4−import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
5−import Streamly.Prelude
9− hSetBuffering stdout LineBuffering
11− putStrLn "\nloopTail:\n"
14− yieldM $ print (x :: Int)
16− putStrLn "\nloopHead:\n"
19− yieldM $ print (x :: Int)
21− putStrLn "\nloopTailA:\n"
24− yieldM $ print (x :: Int)
26− putStrLn "\nloopHeadA:\n"
29− yieldM $ print (x :: Int)
31− putStrLn "\nwSerial:\n"
33− x <- (return 0 <> return 1) `wSerial` (return 100 <> return 101)
34− yieldM $ print (x :: Int)
36− putStrLn "\nParallel interleave:\n"
38− x <- (return 0 <> return 1) `wAsync` (return 100 <> return 101)
39− yieldM $ print (x :: Int)
43−-------------------------------------------------------------------------------
44−-- Serial (single-threaded) stream generator loops
45−-------------------------------------------------------------------------------
47− -- Generates a value and then loops. Can be used to generate an infinite
48− -- stream. Interleaves the generator and the consumer.
49− loopTail :: Int -> Serial Int
51− yieldM $ putStrLn "LoopTail..."
52− return x <> (if x < 3 then loopTail (x + 1) else nil)
54− -- Loops and then generates a value. The consumer can run only after the
55− -- loop has finished. An infinite generator will not let the consumer run
57− loopHead :: Int -> Serial Int
59− yieldM $ putStrLn "LoopHead..."
60− (if x < 3 then loopHead (x + 1) else nil) <> return x
62−-------------------------------------------------------------------------------
63−-- Concurrent (multi-threaded) adaptive demand-based stream generator loops
64−-------------------------------------------------------------------------------
66− loopTailA :: Int -> Serial Int
68− yieldM $ putStrLn "LoopTailA..."
69− return x `async` (if x < 3 then loopTailA (x + 1) else nil)
71− loopHeadA :: Int -> Serial Int
73− yieldM $ putStrLn "LoopHeadA..."
74− (if x < 3 then loopHeadA (x + 1) else nil) `async` return x
76−-------------------------------------------------------------------------------
77−-- Parallel (fairly scheduled, multi-threaded) stream generator loops
78−-------------------------------------------------------------------------------