on a526207 help sign in
streamly/src/Streamly/Examples/ListDirRecursive.hs
18 lines 753 B history raw
1module Streamly.Examples.ListDirRecursive where
3import Control.Monad.IO.Class (liftIO)
4import Path.IO (listDir, getCurrentDir)
5import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
6import Streamly (runStream, coparallely)
8-- | This example demonstrates that there is little difference between regular
9-- IO code and concurrent streamly code. You can just remove
10-- 'runStream . coparallely' and this becomes your regular IO code.
11listDirRecursive :: IO ()
12listDirRecursive = do
13 hSetBuffering stdout LineBuffering
14 runStream . coparallely $ getCurrentDir >>= readdir
15 where readdir d = do
16 (ds, fs) <- liftIO $ listDir d
17 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
18 foldMap readdir ds