on 57fad21 help sign in
streamly/examples/ListDir.hs
18 lines 740 B history raw
1import Control.Monad.IO.Class (liftIO)
2import Path.IO (listDir, getCurrentDir)
3import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
4import Streamly (runStream, aheadly, (<>))
6-- | List the current directory recursively using concurrent processing
7--
8-- This example demonstrates that there is little difference between regular
9-- IO code and concurrent streamly code. You can just remove
10-- 'runStream . aheadly' and this becomes your regular IO code.
11main :: IO ()
12main = do
13 hSetBuffering stdout LineBuffering
14 runStream . aheadly $ getCurrentDir >>= readdir
15 where readdir d = do
16 (ds, fs) <- listDir d
17 liftIO $ mapM_ putStrLn $ fmap show fs <> fmap show ds
18 foldMap readdir ds