on master help sign in
Add some more examples
commitb68840b6e6d278e854ca0730e7f1a00f73631385 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 24 Aug 2017, 02:22 (9 years ago) parent5349a44
2 files changed+30
examples/echo-loop.hs+16 examples/listdir.hs+14
examples/echo-loop.hsnew file+16
@@ -0,0 +1,16 @@
1+import Control.Monad.IO.Class (liftIO)
2+import Data.Monoid ((<>))
3+
4+import Asyncly (AsynclyT, runAsyncly)
5+
6+input :: AsynclyT IO String
7+input = do
8+ string <- liftIO getLine
9+ return string <> input
10+
11+output :: AsynclyT IO String -> AsynclyT IO ()
12+output strings = do
13+ s <- strings
14+ liftIO $ putStrLn s
15+
16+main = runAsyncly $ output input
examples/listdir.hsnew file+14
@@ -0,0 +1,14 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+
3+import Control.Monad.IO.Class (liftIO)
4+import Control.Monad.Trans.Class (lift)
5+import Path.IO (listDir, getCurrentDir)
6+import Path (Path, Dir, reldir)
7+import Asyncly
8+
9+main = runAsyncly $ getCurrentDir >>= readdir
10+ where readdir d = do
11+ (ds, fs) <- lift $ listDir d
12+ liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
13+ for ds readdir -- concurrent version
14+ -- each ds >>= readdir -- serial version