diff options
author | Łukasz Hanuszczak <lukasz.hanuszczak@gmail.com> | 2015-08-18 18:06:59 +0200 |
---|---|---|
committer | Łukasz Hanuszczak <lukasz.hanuszczak@gmail.com> | 2015-08-22 23:40:27 +0200 |
commit | 163da5a4b6268de54594e18f69f06799df637305 (patch) | |
tree | 13a97fcb00b20b7ffd11cc59729e9d5608f057dd /haddock-test | |
parent | 5568091a53ee53f742b6fe9f11b3edd1664228b9 (diff) |
Create utility function for recursive obtaining directory contents.
Diffstat (limited to 'haddock-test')
-rw-r--r-- | haddock-test/src/Test/Haddock/Utils.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/haddock-test/src/Test/Haddock/Utils.hs b/haddock-test/src/Test/Haddock/Utils.hs index 1d57107f..4640fe97 100644 --- a/haddock-test/src/Test/Haddock/Utils.hs +++ b/haddock-test/src/Test/Haddock/Utils.hs @@ -1,8 +1,33 @@ module Test.Haddock.Utils where +import Control.Monad + import Data.Maybe +import System.Directory +import System.FilePath + mlast :: [a] -> Maybe a mlast = listToMaybe . reverse + + +partitionM :: Monad m => (a -> m Bool) -> [a] -> m ([a], [a]) +partitionM _ [] = pure ([], []) +partitionM p (x:xs) = do + (ss, fs) <- partitionM p xs + b <- p x + pure $ if b then (x:ss, fs) else (ss, x:fs) + + +getDirectoryTree :: FilePath -> IO [FilePath] +getDirectoryTree path = do + (dirs, files) <- partitionM isDirectory =<< contents + subfiles <- fmap concat . forM dirs $ \dir -> + map (dir </>) <$> getDirectoryTree (path </> dir) + pure $ files ++ subfiles + where + contents = filter realEntry <$> getDirectoryContents path + isDirectory entry = doesDirectoryExist $ path </> entry + realEntry entry = not $ entry == "." || entry == ".." |