on master help sign in
Fix examples in README
5ef2bfeHarendra Kumar
README.md+23−14
@@ -29,9 +29,12 @@ the comprehensive tutorial module `Streamly.Tutorial` first. Also see
29The monad instance composes like a list monad.
29The monad instance composes like a list monad.
30
30
31``` haskell
31``` haskell
32+import Streamly
33+import qualified Streamly.Prelude as S
34+
32−loops = $ do
35+loops = do
33− x <- each [1,2]
36+ x <- S.each [1,2]
34− y <- each [3,4]
37+ y <- S.each [3,4]
35 liftIO $ putStrLn $ show (x, y)
38 liftIO $ putStrLn $ show (x, y)
36
39
37main = runStreaming $ serially $ loops
40main = runStreaming $ serially $ loops
@@ -69,13 +72,17 @@ You can fold multiple streams or IO actions using parallel combinators like
69concurrently sum the square roots of all combinations:
72concurrently sum the square roots of all combinations:
70
73
71``` haskell
74``` haskell
75+import Streamly
76+import qualified Streamly.Prelude as S
77+
72main = do
78main = do
73− print $ sum $ asyncly $ do
79+ s <- S.sum $ asyncly $ do
74− -- Squaring is concurrent (<|)
80+ -- Squaring is concurrent (<|)
75− x2 <- forEachWith (<|) [1..100] $ \x -> return $ x * x
81+ x2 <- forEachWith (<|) [1..100] $ \x -> return $ x * x
76− y2 <- forEachWith (<|) [1..100] $ \y -> return $ y * y
82+ y2 <- forEachWith (<|) [1..100] $ \y -> return $ y * y
77− -- sqrt is concurrent (asyncly)
83+ -- sqrt is concurrent (asyncly)
78− return $ sqrt (x2 + y2)
84+ return $ sqrt (x2 + y2)
85+ print s
79```
86```
80
87
81Of course, the actions running in parallel could be arbitrary IO actions. To
88Of course, the actions running in parallel could be arbitrary IO actions. To
@@ -144,11 +151,13 @@ main = S.each [1..10]
144Streams can be combined together in multiple ways:
151Streams can be combined together in multiple ways:
145
152
146```haskell
153```haskell
154+main = do
155+ let p s = (toList . serially) s >>= print
147−return 1 <> return 2 -- serial, combine atoms
156+ p $ return 1 <> return 2 -- serial, combine atoms
148−S.each [1..10] <> S.each [11..20] -- serial
157+ p $ S.each [1..10] <> S.each [11..20] -- serial
149−S.each [1..10] <| S.each [11..20] -- demand driven parallel
158+ p $ S.each [1..10] <| S.each [11..20] -- demand driven parallel
150−S.each [1..10] <=> S.each [11..20] -- serial but interleaved
159+ p $ S.each [1..10] <=> S.each [11..20] -- serial but interleaved
151−S.each [1..10] <|> S.each [11..20] -- fully parallel
160+ p $ S.each [1..10] <|> S.each [11..20] -- fully parallel
152```
161```
153
162
154As we have already seen streams can be combined using monadic composition in a
163As we have already seen streams can be combined using monadic composition in a