2import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
3import Streamly.Prelude (nil, yieldM)
6 hSetBuffering stdout LineBuffering
8 putStrLn $ "\nloopTail:\n"
11 yieldM $ print (x :: Int)
13 putStrLn $ "\nloopHead:\n"
16 yieldM $ print (x :: Int)
18 putStrLn $ "\nloopTailA:\n"
21 yieldM $ print (x :: Int)
23 putStrLn $ "\nloopHeadA:\n"
26 yieldM $ print (x :: Int)
28 putStrLn $ "\nwSerial:\n"
30 x <- (return 0 <> return 1) `wSerial` (return 100 <> return 101)
31 yieldM $ print (x :: Int)
33 putStrLn $ "\nParallel interleave:\n"
35 x <- (return 0 <> return 1) `wAsync` (return 100 <> return 101)
36 yieldM $ print (x :: Int)
40-------------------------------------------------------------------------------
41-- Serial (single-threaded) stream generator loops
42-------------------------------------------------------------------------------
44 -- Generates a value and then loops. Can be used to generate an infinite
45 -- stream. Interleaves the generator and the consumer.
46 loopTail :: Int -> Serial Int
48 yieldM $ putStrLn "LoopTail..."
49 return x <> (if x < 3 then loopTail (x + 1) else nil)
51 -- Loops and then generates a value. The consumer can run only after the
52 -- loop has finished. An infinite generator will not let the consumer run
54 loopHead :: Int -> Serial Int
56 yieldM $ putStrLn "LoopHead..."
57 (if x < 3 then loopHead (x + 1) else nil) <> return x
59-------------------------------------------------------------------------------
60-- Concurrent (multi-threaded) adaptive demand-based stream generator loops
61-------------------------------------------------------------------------------
63 loopTailA :: Int -> Serial Int
65 yieldM $ putStrLn "LoopTailA..."
66 return x `async` (if x < 3 then loopTailA (x + 1) else nil)
68 loopHeadA :: Int -> Serial Int
70 yieldM $ putStrLn "LoopHeadA..."
71 (if x < 3 then loopHeadA (x + 1) else nil) `async` return x
73-------------------------------------------------------------------------------
74-- Parallel (fairly scheduled, multi-threaded) stream generator loops
75-------------------------------------------------------------------------------
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list