on 4172ad9 help sign in
streamly/examples/ListDir.hs
31 lines 1.1 kB history raw
1module Main (main) where
3import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
4import Streamly (async)
5import Data.Function ((&))
7import qualified Streamly.Prelude as S
8import qualified Streamly.Internal.Prelude as S
9import qualified Streamly.Internal.FileSystem.Dir as Dir
11-- | List the current directory recursively using concurrent processing
12--
13main :: IO ()
14main = do
15 hSetBuffering stdout LineBuffering
16 -- XXX Fix bug in enqueueAhead when mixing serial with ahead:
17 -- (\x -> S.yield dir <> S.concatMapWith ahead recursePath x)
18 -- :: SerialT IO String
19 -- or S.cons dir . S.concatMapWith ahead recursePath
20 S.mapM_ print $ S.concatMapTreeWith async listDir
21 (S.yieldM $ return (Left "."))
23 where
25 listDir dir =
26 Dir.toEither dir -- SerialT IO (Either String String)
27 & S.map (prefixDir dir) -- SerialT IO (Either String String)
29 prefixDir :: String -> Either String String -> Either String String
30 prefixDir dir (Right x) = Right $ dir ++ "/" ++ x
31 prefixDir dir (Left x) = Left $ dir ++ "/" ++ x