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