2import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
3import Streamly.Prelude (nil, yieldM)
7 hSetBuffering stdout LineBuffering
9 putStrLn "\nloopTail:\n"
12 yieldM $ print (x :: Int)
14 putStrLn "\nloopHead:\n"
17 yieldM $ print (x :: Int)
19 putStrLn "\nloopTailA:\n"
22 yieldM $ print (x :: Int)
24 putStrLn "\nloopHeadA:\n"
27 yieldM $ print (x :: Int)
29 putStrLn "\nwSerial:\n"
31 x <- (return 0 <> return 1) `wSerial` (return 100 <> return 101)
32 yieldM $ print (x :: Int)
34 putStrLn "\nParallel interleave:\n"
36 x <- (return 0 <> return 1) `wAsync` (return 100 <> return 101)
37 yieldM $ print (x :: Int)
41-------------------------------------------------------------------------------
42-- Serial (single-threaded) stream generator loops
43-------------------------------------------------------------------------------
45 -- Generates a value and then loops. Can be used to generate an infinite
46 -- stream. Interleaves the generator and the consumer.
47 loopTail :: Int -> Serial Int
49 yieldM $ putStrLn "LoopTail..."
50 return x <> (if x < 3 then loopTail (x + 1) else nil)
52 -- Loops and then generates a value. The consumer can run only after the
53 -- loop has finished. An infinite generator will not let the consumer run
55 loopHead :: Int -> Serial Int
57 yieldM $ putStrLn "LoopHead..."
58 (if x < 3 then loopHead (x + 1) else nil) <> return x
60-------------------------------------------------------------------------------
61-- Concurrent (multi-threaded) adaptive demand-based stream generator loops
62-------------------------------------------------------------------------------
64 loopTailA :: Int -> Serial Int
66 yieldM $ putStrLn "LoopTailA..."
67 return x `async` (if x < 3 then loopTailA (x + 1) else nil)
69 loopHeadA :: Int -> Serial Int
71 yieldM $ putStrLn "LoopHeadA..."
72 (if x < 3 then loopHeadA (x + 1) else nil) `async` return x
74-------------------------------------------------------------------------------
75-- Parallel (fairly scheduled, multi-threaded) stream generator loops
76-------------------------------------------------------------------------------
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