on master help sign in
Add readEitherPaths to Dir module
commitd6679cb061e062c52f47437171eae29c95943767 authorHarendra Kumar <harendra@composewell.com> dateWed 28 Dec 2022, 08:22 (4 years ago) parentb56e0a1
2 files changed+11−1
core/src/Streamly/Internal/FileSystem/Dir.hs+10−1 core/streamly-core.cabal+1
core/src/Streamly/Internal/FileSystem/Dir.hs+10−1
@@ -34,6 +34,7 @@ module Streamly.Internal.FileSystem.Dir
3434 , readFiles
3535 , readDirs
3636 , readEither
37+ , readEitherPaths
3738
3839 -- We can implement this in terms of readAttrsRecursive without losing
3940 -- perf.
@@ -82,9 +83,11 @@ module Streamly.Internal.FileSystem.Dir
8283where
8384
8485import Control.Monad.IO.Class (MonadIO(..))
86+import Data.Bifunctor (bimap)
8587import Data.Either (isRight, isLeft, fromLeft, fromRight)
8688import Streamly.Data.Stream (Stream)
8789import Streamly.Internal.Data.Unfold.Type (Unfold(..))
90+import System.FilePath ((</>))
8891
8992import qualified Streamly.Data.Unfold as UF
9093import qualified Streamly.Internal.Data.Unfold as UF (mapM2)
@@ -288,13 +291,19 @@ toStream :: MonadIO m => String -> Stream m String
288291toStream = read
289292
290293-- | Read directories as Left and files as Right. Filter out "." and ".."
291−-- entries.
294+-- entries. The output contains the names of the directories and files.
292295--
293296-- /Pre-release/
294297{-# INLINE readEither #-}
295298readEither :: MonadIO m => FilePath -> Stream m (Either FilePath FilePath)
296299readEither = S.unfold eitherReader
297300
301+-- | Like 'readEither' but prefix the names of the files and directories with
302+-- the supplied directory path.
303+{-# INLINE readEitherPaths #-}
304+readEitherPaths :: MonadIO m => FilePath -> Stream m (Either FilePath FilePath)
305+readEitherPaths dir = fmap (bimap (dir </>) (dir </>)) $ readEither dir
306+
298307{-# DEPRECATED toEither "Please use 'readEither' instead" #-}
299308{-# INLINE toEither #-}
300309toEither :: MonadIO m => FilePath -> Stream m (Either FilePath FilePath)
core/streamly-core.cabal+1
@@ -434,6 +434,7 @@ library
434434 , base >= 4.12 && < 4.18
435435 , exceptions >= 0.8.0 && < 0.11
436436 , transformers >= 0.5.5 && < 0.7
437+ , filepath >= 1.4.2 && < 1.5
437438
438439 -- streamly-unicode-core
439440 , template-haskell >= 2.14 && < 2.20