on 5054813 help sign in
streamly/examples/ListDir.hs
25 lines 773 B history raw
1module Main (main) where
3import Data.Bifunctor (bimap)
4import Data.Function ((&))
5import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
6import Streamly (ahead)
8import qualified Streamly.Prelude as S
9import qualified Streamly.Internal.Prelude as S
10import qualified Streamly.Internal.FileSystem.Dir as Dir
12-- | List the current directory recursively using concurrent processing
13--
14main :: IO ()
15main = do
16 hSetBuffering stdout LineBuffering
17 S.mapM_ print $ S.concatMapTreeWith ahead listDir
18 (S.yieldM $ return (Left "."))
20 where
22 listDir dir =
23 Dir.toEither dir -- SerialT IO (Either String String)
24 & S.map (bimap prefix prefix) -- SerialT IO (Either String String)
25 where prefix x = dir ++ "/" ++ x