@@ -29,9 +29,12 @@ the comprehensive tutorial module `Streamly.Tutorial` first. Also see
2929The monad instance composes like a list monad.
3030
3131``` haskell
32−loops = $ do
33− x <- each [1,2]
34− y <- each [3,4]
32+import Streamly
33+import qualified Streamly.Prelude as S
34+
35+loops = do
36+ x <- S.each [1,2]
37+ y <- S.each [3,4]
3538 liftIO $ putStrLn $ show (x, y)
3639
3740main = runStreaming $ serially $ loops
@@ -69,13 +72,17 @@ You can fold multiple streams or IO actions using parallel combinators like
6972concurrently sum the square roots of all combinations:
7073
7174``` haskell
75+import Streamly
76+import qualified Streamly.Prelude as S
77+
7278main = do
73− print $ sum $ asyncly $ do
74− -- Squaring is concurrent (<|)
75− x2 <- forEachWith (<|) [1..100] $ \x -> return $ x * x
76− y2 <- forEachWith (<|) [1..100] $ \y -> return $ y * y
77− -- sqrt is concurrent (asyncly)
78− return $ sqrt (x2 + y2)
79+ s <- S.sum $ asyncly $ do
80+ -- Squaring is concurrent (<|)
81+ x2 <- forEachWith (<|) [1..100] $ \x -> return $ x * x
82+ y2 <- forEachWith (<|) [1..100] $ \y -> return $ y * y
83+ -- sqrt is concurrent (asyncly)
84+ return $ sqrt (x2 + y2)
85+ print s
7986```
8087
8188Of course, the actions running in parallel could be arbitrary IO actions. To
@@ -144,11 +151,13 @@ main = S.each [1..10]
144151Streams can be combined together in multiple ways:
145152
146153```haskell
147−return 1 <> return 2 -- serial, combine atoms
148−S.each [1..10] <> S.each [11..20] -- serial
149−S.each [1..10] <| S.each [11..20] -- demand driven parallel
150−S.each [1..10] <=> S.each [11..20] -- serial but interleaved
151−S.each [1..10] <|> S.each [11..20] -- fully parallel
154+main = do
155+ let p s = (toList . serially) s >>= print
156+ p $ return 1 <> return 2 -- serial, combine atoms
157+ p $ S.each [1..10] <> S.each [11..20] -- serial
158+ p $ S.each [1..10] <| S.each [11..20] -- demand driven parallel
159+ p $ S.each [1..10] <=> S.each [11..20] -- serial but interleaved
160+ p $ S.each [1..10] <|> S.each [11..20] -- fully parallel
152161```
153162
154163As we have already seen streams can be combined using monadic composition in a