@@ -72,6 +72,9 @@ pipeline, just the standard forward (`$`) or reverse (`&`) function application
72operator is enough. Combinators are provided in `Streamly.Prelude` to
72operator is enough. Combinators are provided in `Streamly.Prelude` to
73transform or fold streams.
73transform or fold streams.
75+This snippet reads numbers from stdin, prints the squares of even numbers and
76+exits if an even number more than 9 is entered.
76import Streamly
79import Streamly
77import qualified Streamly.Prelude as S
80import qualified Streamly.Prelude as S
@@ -112,9 +115,9 @@ import qualified Streamly.Prelude as S
112import Control.Concurrent
115import Control.Concurrent
114delay n = S.once $ do
117delay n = S.once $ do
115− threadDelay (n * 1000000)
118+ threadDelay (n * 1000000)
116− tid <- myThreadId
119+ tid <- myThreadId
117− putStrLn (show tid ++ ": Delay " ++ show n)
120+ putStrLn (show tid ++ ": Delay " ++ show n)
119### Serial
122### Serial
@@ -203,7 +206,7 @@ main = do
203 s <- S.sum $ asyncly $ do
206 s <- S.sum $ asyncly $ do
204 -- Each square is performed concurrently, (<>) is concurrent
207 -- Each square is performed concurrently, (<>) is concurrent
205 x2 <- foldMap (\x -> return $ x * x) [1..100]
208 x2 <- foldMap (\x -> return $ x * x) [1..100]
206− y2 <- foldMap (\y -> return $ x * x) [1..100]
209+ y2 <- foldMap (\y -> return $ y * y) [1..100]
207 -- Each addition is performed concurrently, monadic bind is concurrent
210 -- Each addition is performed concurrently, monadic bind is concurrent
208 return $ sqrt (x2 + y2)
211 return $ sqrt (x2 + y2)
@@ -215,6 +218,7 @@ example, to concurrently list the contents of a directory tree recursively:
215``` haskell
218``` haskell
216import Path.IO (listDir, getCurrentDir)
219import Path.IO (listDir, getCurrentDir)
217import Streamly
220import Streamly
221+import qualified Streamly.Prelude as S
219main = runStream $ asyncly $ getCurrentDir >>= readdir
223main = runStream $ asyncly $ getCurrentDir >>= readdir
220 where readdir d = do
224 where readdir d = do
@@ -226,7 +230,7 @@ main = runStream $ asyncly $ getCurrentDir >>= readdir
227In the above examples we do not think in terms of threads, locking or
231In the above examples we do not think in terms of threads, locking or
228synchronization, rather we think in terms of what can run in parallel, the rest
232synchronization, rather we think in terms of what can run in parallel, the rest
229−is taken care of automatically. When using `coparallely` the programmer does
233+is taken care of automatically. When using `asyncly` the programmer does
230not have to worry about how many threads are to be created they are
234not have to worry about how many threads are to be created they are
231automatically adjusted based on the demand of the consumer.
235automatically adjusted based on the demand of the consumer.