Use ahead and bimap

This commit is contained in:
Harendra Kumar 2019-12-03 12:20:30 +05:30
parent 00f541e6d5
commit 785630e7e1

View File

@ -1,8 +1,9 @@
module Main (main) where
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
import Streamly (async)
import Data.Bifunctor (bimap)
import Data.Function ((&))
import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
import Streamly (ahead)
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Prelude as S
@ -13,19 +14,12 @@ import qualified Streamly.Internal.FileSystem.Dir as Dir
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.mapM_ print $ S.concatMapTreeWith ahead 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
& S.map (bimap prefix prefix) -- SerialT IO (Either String String)
where prefix x = dir ++ "/" ++ x