-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathListDir.hs
31 lines (25 loc) · 1.08 KB
/
ListDir.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Main (main) where
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
import Streamly (async)
import Data.Function ((&))
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Prelude as S
import qualified Streamly.Internal.FileSystem.Dir as Dir
-- | List the current directory recursively using concurrent processing
--
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
-- XXX Fix bug in enqueueAhead when mixing serial with ahead:
-- (\x -> S.yield dir <> S.concatMapWith ahead recursePath x)
-- :: SerialT IO String
-- or S.cons dir . S.concatMapWith ahead recursePath
S.mapM_ print $ S.concatMapTreeWith async listDir
(S.yieldM $ return (Left "."))
where
listDir dir =
Dir.toEither dir -- SerialT IO (Either String String)
& S.map (prefixDir dir) -- SerialT IO (Either String String)
prefixDir :: String -> Either String String -> Either String String
prefixDir dir (Right x) = Right $ dir ++ "/" ++ x
prefixDir dir (Left x) = Left $ dir ++ "/" ++ x