module CabalGild.Class.MonadWalk where import qualified System.Directory as Directory import qualified System.FilePath as FilePath class (Monad m) => MonadWalk m where walk :: FilePath -> m [FilePath] instance MonadWalk IO where walk :: FilePath -> IO [FilePath] walk = FilePath -> IO [FilePath] listDirectoryRecursively listDirectoryRecursively :: FilePath -> IO [FilePath] listDirectoryRecursively :: FilePath -> IO [FilePath] listDirectoryRecursively FilePath d = do [FilePath] es <- FilePath -> IO [FilePath] Directory.listDirectory FilePath d let f :: FilePath -> IO [FilePath] f FilePath e = do let p :: FilePath p = FilePath -> FilePath -> FilePath FilePath.combine FilePath d FilePath e Bool b <- FilePath -> IO Bool Directory.doesDirectoryExist FilePath p if Bool b then FilePath -> IO [FilePath] listDirectoryRecursively FilePath p else [FilePath] -> IO [FilePath] forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure [FilePath p] [[FilePath]] -> [FilePath] forall (t :: * -> *) a. Foldable t => t [a] -> [a] concat ([[FilePath]] -> [FilePath]) -> IO [[FilePath]] -> IO [FilePath] forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (FilePath -> IO [FilePath]) -> [FilePath] -> IO [[FilePath]] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b] mapM FilePath -> IO [FilePath] f [FilePath] es