packages feed

FilePather 0.0.2 → 0.1.0

raw patch · 9 files changed

+484/−414 lines, 9 filesdep +comonaddep +mtldep +transformersdep ~directorydep ~filepathPVP ok

version bump matches the API change (PVP)

Dependencies added: comonad, mtl, transformers

Dependency ranges changed: directory, filepath

API changes (from Hackage documentation)

- System.FilePath.FilePather: (<?>) :: FilePather a -> FilePath -> a
- System.FilePath.FilePather: Directory :: FileType
- System.FilePath.FilePather: File :: FileType
- System.FilePath.FilePather: Unknown :: FileType
- System.FilePath.FilePather: always :: FilePather Bool
- System.FilePath.FilePather: always' :: FilePather (a -> Bool)
- System.FilePath.FilePather: baseName :: FilePather FilePath
- System.FilePath.FilePather: baseName' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: data FilePather a
- System.FilePath.FilePather: data FileType
- System.FilePath.FilePather: directory :: FilePather FilePath
- System.FilePath.FilePather: directory' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: extension :: FilePather FilePath
- System.FilePath.FilePather: extension' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: extensionEq :: FilePath -> FilterPredicate
- System.FilePath.FilePather: extensionOneOf :: [FilePath] -> FilterPredicate
- System.FilePath.FilePather: extensionSatisfies :: (FilePath -> Bool) -> FilterPredicate
- System.FilePath.FilePather: fileName :: FilePather FilePath
- System.FilePath.FilePather: fileName' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: filePath :: FilePather FilePath
- System.FilePath.FilePather: filePather :: (FilePath -> a) -> FilePather a
- System.FilePath.FilePather: find :: RecursePredicate -> FilterPredicate -> FilePath -> IO [FilePath]
- System.FilePath.FilePather: findHere :: RecursePredicate -> FilterPredicate -> IO [FilePath]
- System.FilePath.FilePather: hasExtension :: FilePather Bool
- System.FilePath.FilePather: hasExtension' :: FilePather (a -> Bool)
- System.FilePath.FilePather: hasTrailingPathSeparator :: FilePather Bool
- System.FilePath.FilePather: hasTrailingPathSeparator' :: FilePather (a -> Bool)
- System.FilePath.FilePather: indir :: FilePath -> (FilePath -> IO a) -> IO a
- System.FilePath.FilePather: indir' :: FilePath -> IO a -> IO a
- System.FilePath.FilePather: instance Applicative FilePather
- System.FilePath.FilePather: instance Eq FileType
- System.FilePath.FilePather: instance Functor FilePather
- System.FilePath.FilePather: instance Monad FilePather
- System.FilePath.FilePather: instance Monoid a => Monoid (FilePather a)
- System.FilePath.FilePather: instance Show FileType
- System.FilePath.FilePather: isAbsolute :: FilePather Bool
- System.FilePath.FilePather: isAbsolute' :: FilePather (a -> Bool)
- System.FilePath.FilePather: isDirectory :: Applicative f => f (FileType -> Bool)
- System.FilePath.FilePather: isFile :: Applicative f => f (FileType -> Bool)
- System.FilePath.FilePather: isRelative :: FilePather Bool
- System.FilePath.FilePather: isRelative' :: FilePather (a -> Bool)
- System.FilePath.FilePather: isUnknown :: Applicative f => f (FileType -> Bool)
- System.FilePath.FilePather: isValid :: FilePather Bool
- System.FilePath.FilePather: isValid' :: FilePather (a -> Bool)
- System.FilePath.FilePather: makeValid :: FilePather FilePath
- System.FilePath.FilePather: makeValid' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: never :: FilePather Bool
- System.FilePath.FilePather: never' :: FilePather (a -> Bool)
- System.FilePath.FilePather: normalise :: FilePather FilePath
- System.FilePath.FilePather: normalise' :: FilePather (a -> FilePath)
- System.FilePath.FilePather: splitDirectories :: FilePather [FilePath]
- System.FilePath.FilePather: splitDirectories' :: FilePather (a -> [FilePath])
- System.FilePath.FilePather: splitExtension :: FilePather (String, String)
- System.FilePath.FilePather: splitExtension' :: FilePather (a -> (String, String))
- System.FilePath.FilePather: type FilterPredicate = FilePather (FileType -> Bool)
- System.FilePath.FilePather: type RecursePredicate = FilePather Bool
+ System.FilePath.FilePather.FilePathPredicate: (.!.) :: (FilePathPredicate f, Monad g) => f g -> f g
+ System.FilePath.FilePather.FilePathPredicate: (.&&.) :: (FilePathPredicate f, Monad g) => f g -> f g -> f g
+ System.FilePath.FilePather.FilePathPredicate: (.||.) :: (FilePathPredicate f, Monad g) => f g -> f g -> f g
+ System.FilePath.FilePather.FilePathPredicate: always :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: baseName :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: class FilePathPredicate f where hasExtension = (.!.) notHasExtension notHasExtension = (.!.) hasExtension hasTrailingPathSeparator = (.!.) notHasTrailingPathSeparator notHasTrailingPathSeparator = (.!.) hasTrailingPathSeparator isRelative = (.!.) isNotRelative isNotRelative = (.!.) isRelative isAbsolute = (.!.) isNotAbsolute isNotAbsolute = (.!.) isAbsolute isValid = (.!.) isNotValid isNotValid = (.!.) isValid
+ System.FilePath.FilePather.FilePathPredicate: directory :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: extension :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: fileName :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: hasExtension :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: hasTrailingPathSeparator :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: instance FilePathPredicate FilterPredicateT
+ System.FilePath.FilePather.FilePathPredicate: instance FilePathPredicate RecursePredicateT
+ System.FilePath.FilePather.FilePathPredicate: isAbsolute :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: isNotAbsolute :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: isNotRelative :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: isNotValid :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: isRelative :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: isValid :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: makeValid :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: never :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: normalise :: (FilePathPredicate f, Monad g) => (FilePath -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: notHasExtension :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: notHasTrailingPathSeparator :: (FilePathPredicate f, Monad g) => f g
+ System.FilePath.FilePather.FilePathPredicate: splitDirectories :: (FilePathPredicate f, Monad g) => ([FilePath] -> Bool) -> f g
+ System.FilePath.FilePather.FilePathPredicate: splitExtension :: (FilePathPredicate f, Monad g) => (String -> String -> Bool) -> f g
+ System.FilePath.FilePather.FileType: Directory :: FileType
+ System.FilePath.FilePather.FileType: File :: FileType
+ System.FilePath.FilePather.FileType: Unknown :: FileType
+ System.FilePath.FilePather.FileType: data FileType
+ System.FilePath.FilePather.FileType: instance Enum FileType
+ System.FilePath.FilePather.FileType: instance Eq FileType
+ System.FilePath.FilePather.FileType: instance Show FileType
+ System.FilePath.FilePather.FilterPredicate: data FilterPredicateT f
+ System.FilePath.FilePather.FilterPredicate: filterPredicate :: (FilePath -> FileType -> Bool) -> FilterPredicate
+ System.FilePath.FilePather.FilterPredicate: filterPredicateT :: (FilePath -> FileType -> f Bool) -> FilterPredicateT f
+ System.FilePath.FilePather.FilterPredicate: runFilterPredicate :: FilterPredicate -> FilePath -> FileType -> Bool
+ System.FilePath.FilePather.FilterPredicate: runFilterPredicateT :: FilterPredicateT f -> FilePath -> FileType -> f Bool
+ System.FilePath.FilePather.FilterPredicate: type FilterPredicate = FilterPredicateT Identity
+ System.FilePath.FilePather.Find: class Find f
+ System.FilePath.FilePather.Find: find :: Find f => FilterPredicateT f -> RecursePredicateT f -> FilePath -> IO [FilePath]
+ System.FilePath.FilePather.Find: instance Comonad f => Find (IdentityT f)
+ System.FilePath.FilePather.Find: instance Find IO
+ System.FilePath.FilePather.Find: instance Find Identity
+ System.FilePath.FilePather.RecursePredicate: data RecursePredicateT f
+ System.FilePath.FilePather.RecursePredicate: recursePredicate :: (FilePath -> Bool) -> RecursePredicate
+ System.FilePath.FilePather.RecursePredicate: recursePredicateT :: (FilePath -> f Bool) -> RecursePredicateT f
+ System.FilePath.FilePather.RecursePredicate: runRecursePredicate :: RecursePredicate -> FilePath -> Bool
+ System.FilePath.FilePather.RecursePredicate: runRecursePredicateT :: RecursePredicateT f -> FilePath -> f Bool
+ System.FilePath.FilePather.RecursePredicate: type RecursePredicate = RecursePredicateT Identity

Files

FilePather.cabal view
@@ -1,5 +1,5 @@ Name:               FilePather-Version:            0.0.2+Version:            0.1.0 Author:             Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> Maintainer:         Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> Copyright:          Tony Morris@@ -24,14 +24,17 @@ Cabal-version:      >= 1.6 Build-Type:         Simple -Flag small_base+Flag                small_base   Description:      Choose the new, split-up base package.  Library   Build-Depends:                     base < 5 && >= 3,-                    directory,-                    filepath,+                    directory >= 1.1,+                    filepath >= 1.2,+                    mtl >= 2,+                    comonad >= 1.1,+                    transformers >= 0.2,                     HUnit,                     QuickCheck,                     test-framework,@@ -41,9 +44,18 @@   GHC-Options:                     -Wall +  Hs-Source-Dirs:+                    src+   Exposed-Modules:                     System.FilePath.FilePather+                    System.FilePath.FilePather.FileType+                    System.FilePath.FilePather.RecursePredicate+                    System.FilePath.FilePather.FilterPredicate+                    System.FilePath.FilePather.FilePathPredicate+                    System.FilePath.FilePather.Find -source-repository  head+Source-Repository  head   type: git   location: git@github.com:tonymorris/filepather.git+
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2011 Tony Morris+Copyright 2012 Tony Morris  All rights reserved. @@ -24,8 +24,4 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF-<<<<<<< HEAD SUCH DAMAGE.-=======-SUCH DAMAGE.->>>>>>> upstream/master
− System/FilePath/FilePather.hs
@@ -1,404 +0,0 @@-module System.FilePath.FilePather-(-  -- * Data type-  FilePather,-  -- * Constructor and unwrapper-  (<?>),-  filePather,-  -- * 'FilePather' values-  filePath,-  always,-  always',-  never,-  never',-  extension,-  extension',-  directory,-  directory',-  hasExtension,-  hasExtension',-  splitExtension,-  splitExtension',-  splitDirectories,-  splitDirectories',-  hasTrailingPathSeparator,-  hasTrailingPathSeparator',-  fileName,-  fileName',-  baseName,-  baseName',-  normalise,-  normalise',-  makeValid,-  makeValid',-  isRelative,-  isRelative',-  isAbsolute,-  isAbsolute',-  isValid,-  isValid',-  -- * Find predicates-  FileType(..),-  RecursePredicate,-  FilterPredicate,-  isFile,-  isDirectory,-  isUnknown,-  -- * Find-  find,-  -- * Combinators-  extensionSatisfies,-  extensionOneOf,-  extensionEq,-  findHere,-  indir,-  indir'-) where--import Control.Exception-import Control.Applicative-import Control.Monad-import Data.Monoid-import System.FilePath((</>), takeExtension, takeDirectory, takeFileName, takeBaseName)-import qualified System.FilePath as P-import System.Directory---- | A function that takes a 'FilePath' and produces a value.-newtype FilePather a = FilePather {-  (<?>) :: FilePath -> a-}--instance Functor FilePather where-  fmap f (FilePather k) =-    FilePather (f . k)--instance Applicative FilePather where-  FilePather f <*> FilePather a =-    FilePather (f <*> a)-  pure =-    FilePather . const--instance Monad FilePather where-  FilePather f >>= k =-    FilePather (f >>= (<?>) . k)-  return =-    pure--instance (Monoid a) => Monoid (FilePather a) where-  mempty =-    return mempty-  FilePather x `mappend` FilePather y =-    FilePather (x `mappend` y)---- | Construct a 'FilePather' from the given function-filePather ::-  (FilePath -> a)-  -> FilePather a-filePather =-  FilePather---- | A value that runs the identity function.-filePath ::-  FilePather FilePath-filePath =-  filePather id---- | A value that always produces the value 'True'.-always ::-  FilePather Bool-always =-  filePather (const True)---- | A value using a constant function that produces the value 'True'.-always' ::-  FilePather (a -> Bool)-always' =-  constant always---- | A value that always produces the value 'False'.-never ::-  FilePather Bool-never =-  filePather (const False)---- | A value that always produces a constant function that produces the value 'False'.-never' ::-  FilePather (a -> Bool)-never' =-  constant never---- | A value that produces the extension of the given 'FilePath'.-extension ::-  FilePather FilePath-extension =-  filePather takeExtension---- | A value using a constant function that produces the extension of the given 'FilePath'.-extension' ::-  FilePather (a -> FilePath)-extension' =-  constant extension---- | A value that produces the directory of the given 'FilePath'.-directory ::-  FilePather FilePath-directory =-  filePather takeDirectory---- | A value using a constant function that produces the directory of the given 'FilePath'.-directory' ::-  FilePather (a -> FilePath)-directory' =-  constant directory---- | A value that produces a value denoting whether or not the given 'FilePath' has an extension.-hasExtension ::-  FilePather Bool-hasExtension =-  filePather P.hasExtension---- | A value using a constant function that produces a value denoting whether or not the given 'FilePath' has an extension.-hasExtension' ::-  FilePather (a -> Bool)-hasExtension' =-  constant hasExtension---- | A value that produces a value splitting the given 'FilePath' by its extension.-splitExtension ::-  FilePather (String, String)-splitExtension =-  filePather P.splitExtension---- | A value using a constant function that produces a value splitting the given 'FilePath' by its extension.-splitExtension' ::-  FilePather (a -> (String, String))-splitExtension' =-  constant splitExtension---- | A value that produces a value splitting the given 'FilePath' into its directories.-splitDirectories ::-  FilePather [FilePath]-splitDirectories =-  filePather P.splitDirectories---- | A value using a constant function that produces a value splitting the given 'FilePath' into its directories.-splitDirectories' ::-  FilePather (a -> [FilePath])-splitDirectories' =-  constant splitDirectories---- | A value that produces a value denoting whether or not the given 'FilePath' has a trailing path separator.-hasTrailingPathSeparator ::-  FilePather Bool-hasTrailingPathSeparator =-  filePather P.hasTrailingPathSeparator---- | A value using a constant function that produces a value denoting whether or not the given 'FilePath' has a trailing path separator.-hasTrailingPathSeparator' ::-  FilePather (a -> Bool)-hasTrailingPathSeparator' =-  constant hasTrailingPathSeparator---- | A value that produces the file name of the given 'FilePath'.-fileName ::-  FilePather FilePath-fileName =-  filePather takeFileName---- | A value using a constant function that produces the file name of the given 'FilePath'.-fileName' ::-  FilePather (a -> FilePath)-fileName' =-  constant fileName---- | A value that produces the base name of the given 'FilePath'.-baseName ::-  FilePather FilePath-baseName =-  filePather takeBaseName---- | A value using a constant function that produces the base name of the given 'FilePath'.-baseName' ::-  FilePather (a -> FilePath)-baseName' =-  constant baseName---- | A value that normalises the given 'FilePath'.-normalise ::-  FilePather FilePath-normalise =-  filePather P.normalise---- | A value using a constant function that normalises the given 'FilePath'.-normalise' ::-  FilePather (a -> FilePath)-normalise' =-  constant normalise---- | A value that makes valid the given 'FilePath'.-makeValid ::-  FilePather FilePath-makeValid =-  filePather P.makeValid---- | A value using a constant function that makes valid the given 'FilePath'.-makeValid' ::-  FilePather (a -> FilePath)-makeValid' =-  constant makeValid---- | A value that produces a value denoting whether or not the given 'FilePath' has is relative.-isRelative ::-  FilePather Bool-isRelative =-  filePather P.isRelative---- | A value using a constant function that produces a value denoting whether or not the given 'FilePath' has is relative.-isRelative' ::-  FilePather (a -> Bool)-isRelative' =-  constant isRelative---- | A value that produces a value denoting whether or not the given 'FilePath' has is absolute.-isAbsolute ::-  FilePather Bool-isAbsolute =-  filePather P.isAbsolute---- | A value using a constant function that produces a value denoting whether or not the given 'FilePath' has is absolute.-isAbsolute' ::-  FilePather (a -> Bool)-isAbsolute' =-  constant isAbsolute---- | A value that produces a value denoting whether or not the given 'FilePath' has is valid.-isValid ::-  FilePather Bool-isValid =-  filePather P.isValid---- | A value using a constant function that produces a value denoting whether or not the given 'FilePath' has is valid.-isValid' ::-  FilePather (a -> Bool)-isValid' =-  constant isValid---- | The possible types of a file.-data FileType = File -- ^ The type is a normal file.-                | Directory -- ^ The type is a directory.-                | Unknown -- ^ The type is unknown.-  deriving (Eq, Show)---- | A recurse predicate takes a 'FilePath' and returns whether or not to continue recursing on that file.-type RecursePredicate = FilePather Bool---- | A filter predicate takes a 'FilePath' and a file type and returns whether or not to filter the value.-type FilterPredicate = FilePather (FileType -> Bool)---- | Compares for equivalence to a 'File' in an applicative functor.-isFile ::-  Applicative f =>-  f (FileType -> Bool)-isFile =-  pure (== File)---- | Compares for equivalence to a 'Directory' in an applicative functor.-isDirectory ::-  Applicative f =>-  f (FileType -> Bool)-isDirectory =-  pure (== Directory)---- | Compares for equivalence to 'Unknown' in an applicative functor.-isUnknown ::-  Applicative f =>-  f (FileType -> Bool)-isUnknown =-  pure (== Unknown)---- | Finds all files using the given recurse predicate and filter predicate in the given file path.-find ::-  RecursePredicate -- ^ The recurse predicate determines whether to continue recursing on the given file path.-  -> FilterPredicate -- ^ The filter predicate determines whether to keep the current file path.-  -> FilePath -- ^ The file path to begin finding files.-  -> IO [FilePath] -- ^ All files found.-find =-  find' []-    where-    find' :: FilePath -> RecursePredicate -> FilterPredicate -> FilePath -> IO [FilePath]-    find' k r x p = let z = if null k then p else k </> p-                        z' t = [z | x <?> z $ t]-                        ifM c t f = do c' <- c-                                       t' <- t-                                       f' <- f-                                       return (if c' then t' else f')-                    in ifM (doesFileExist z)-                         (return (z' File)) $-                         do e <- doesDirectoryExist z-                            if e-                              then if r <?> z-                                     then do c <- getDirectoryContents z-                                             t <- fmap join $ forM (filter (`notElem` [".", ".."]) c) (find' k r x . (z </>))-                                             return (z' Directory ++ t)-                                     else return (z' Directory)-                              else return (z' Unknown)---- | Returns a filter predicate based on whether a file extension satisfies a predicate.-extensionSatisfies ::-  (FilePath -> Bool)-  -> FilterPredicate-extensionSatisfies f =-  (const . f) <$> extension---- | Returns a filter predicate based on whether a file extension is one of the given list of extensions.-extensionOneOf ::-  [FilePath]-  -> FilterPredicate-extensionOneOf =-  extensionSatisfies . flip elem . map ('.':)---- | Returns a filter predicate based on whether a file extension equals the given extension.-extensionEq ::-  FilePath-  -> FilterPredicate-extensionEq =-  extensionOneOf . return---- | Find in the current directory.-findHere ::-  RecursePredicate -- ^ The recurse predicate determines whether to continue recursing on the given file path.-  -> FilterPredicate -- ^ The filter predicate determines whether to keep the current file path.-  -> IO [FilePath] -- ^ All files found.-findHere r x =-  find r x =<< getCurrentDirectory---- | Switches to the given directory, runs the given action by passing the current directory and running in the switched directory, then returns to the current directory. The directory is switched back, even if an exception occurs during execution of the action.------ | This is useful to run a script in a different directory without switching to it and back again.-indir ::-  FilePath -- ^ The directory to switch to.-  -> (FilePath -> IO a) -- ^ The action to run after being given the current directory.-  -> IO a -- ^ The result of running the action in the switched directory.-indir d k =-  do c <- getCurrentDirectory-     setCurrentDirectory d-     k c `finally` setCurrentDirectory c---- | Switches to the given directory, runs the given action and running in the switched directory, then returns to the current directory. The directory is switched back, even if an exception occurs during execution of the action.------ | This is useful to run a script in a different directory without switching to it and back again.-indir' ::-  FilePath -- ^ The directory to switch to.-  -> IO a -- ^ The action to run.-  -> IO a -- ^ The result of running the action in the switched directory.-indir' d =-  indir d . const---- not exported-constant ::-  Functor f =>-  f a-  -> f (t -> a)-constant =-  fmap const-
+ src/System/FilePath/FilePather.hs view
@@ -0,0 +1,8 @@+module System.FilePath.FilePather(module X) where++import System.FilePath.FilePather.FileType as X+import System.FilePath.FilePather.RecursePredicate as X+import System.FilePath.FilePather.FilterPredicate as X+import System.FilePath.FilePather.FilePathPredicate as X+import System.FilePath.FilePather.Find as X+
+ src/System/FilePath/FilePather/FilePathPredicate.hs view
@@ -0,0 +1,234 @@+module System.FilePath.FilePather.FilePathPredicate+(+  FilePathPredicate(..)+) where++import qualified System.FilePath as P+import System.FilePath.FilePather.RecursePredicate+import System.FilePath.FilePather.FilterPredicate+import Control.Monad++-- | Functions that are common to predicates that work on 'FilePath' values.+class FilePathPredicate f where+  -- | A predicate that always succeeds.+  always ::+    Monad g =>+    f g+  -- | A predicate that always fails.+  never ::+    Monad g =>+    f g+  -- | Return a predicate that succeeds only if the two given predicates succeed.+  (.&&.) ::+    Monad g =>+    f g+    -> f g+    -> f g+  -- | Return a predicate that succeeds if any of the two given predicates succeed.+  (.||.) ::+    Monad g =>+    f g+    -> f g+    -> f g+  -- | Negates the given predicate.+  (.!.) ::+    Monad g =>+    f g+    -> f g+  -- | A predicate that computes its result based on a file name extension.+  extension ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that computes its result based on a directory.+  directory ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that succeeds if its 'FilePath' has an extension.+  hasExtension ::+    Monad g =>+    f g+  hasExtension =+    (.!.) notHasExtension+  -- | A predicate that succeeds if its 'FilePath' does not have an extension.+  notHasExtension ::+    Monad g =>+    f g+  notHasExtension =+    (.!.) hasExtension+  -- | A predicate that computes its result based on the splitting of a name and extension.+  splitExtension ::+    Monad g =>+    (String -> String -> Bool)+    -> f g+  -- | A predicate that computes its result based on the splitting of a name into directories.+  splitDirectories ::+    Monad g =>+    ([FilePath] -> Bool)+    -> f g+  -- | A predicate that succeeds if its 'FilePath' has a trailing path separator.+  hasTrailingPathSeparator ::+    Monad g =>+    f g+  hasTrailingPathSeparator =+    (.!.) notHasTrailingPathSeparator+  -- | A predicate that succeeds if its 'FilePath' does not have a trailing path separator.+  notHasTrailingPathSeparator::+    Monad g =>+    f g+  notHasTrailingPathSeparator =+    (.!.) hasTrailingPathSeparator+  -- | A predicate that computes its result based on the file name.+  fileName ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that computes its result based on the base name.+  baseName ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that computes its result based on the normalised file name.+  normalise ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that computes its result based on the file name having been made valid.+  makeValid ::+    Monad g =>+    (FilePath -> Bool)+    -> f g+  -- | A predicate that succeeds if its 'FilePath' is relative.+  isRelative ::+    Monad g =>+    f g+  isRelative =+    (.!.) isNotRelative+  -- | A predicate that succeeds if its 'FilePath' is not relative.+  isNotRelative ::+    Monad g =>+    f g+  isNotRelative =+    (.!.) isRelative+  -- | A predicate that succeeds if its 'FilePath' is absolute.+  isAbsolute ::+    Monad g =>+    f g+  isAbsolute =+    (.!.) isNotAbsolute+  -- | A predicate that succeeds if its 'FilePath' is not absolute.+  isNotAbsolute ::+    Monad g =>+    f g+  isNotAbsolute =+    (.!.) isAbsolute+  -- | A predicate that succeeds if its 'FilePath' is valid.+  isValid ::+    Monad g =>+    f g+  isValid =+    (.!.) isNotValid+  -- | A predicate that succeeds if its 'FilePath' is not valid.+  isNotValid ::+    Monad g =>+    f g+  isNotValid =+    (.!.) isValid++instance FilePathPredicate RecursePredicateT where+  always =+    recursePredicateT . const . return $ True+  never =+    recursePredicateT . const . return $ False+  f .&&. g =+    recursePredicateT $ \p -> do r <- runRecursePredicateT f p+                                 if r+                                   then+                                     runRecursePredicateT g p+                                   else+                                     return False+  f .||. g =+    recursePredicateT $ \p -> do r <- runRecursePredicateT f p+                                 if r+                                   then+                                     return True+                                   else+                                     runRecursePredicateT g p+  (.!.) f =+    recursePredicateT $ liftM not . runRecursePredicateT f+  extension f = +    recursePredicateT $ return . f . P.takeExtension+  directory f = +    recursePredicateT $ return . f . P.takeDirectory+  hasExtension =+    recursePredicateT $ return . P.hasExtension+  splitExtension f =+    recursePredicateT $ return . uncurry f . P.splitExtension+  splitDirectories f = +    recursePredicateT $ return . f . P.splitDirectories+  hasTrailingPathSeparator =+    recursePredicateT $ return . P.hasTrailingPathSeparator+  fileName f = +    recursePredicateT $ return . f . P.takeFileName+  baseName f = +    recursePredicateT $ return . f . P.takeBaseName+  normalise f = +    recursePredicateT $ return . f . P.normalise+  makeValid f = +    recursePredicateT $ return . f . P.makeValid+  isRelative =+    recursePredicateT $ return . P.isRelative+  isAbsolute =+    recursePredicateT $ return . P.isAbsolute+  isValid =+    recursePredicateT $ return . P.isValid++instance FilePathPredicate FilterPredicateT where+  always =+    filterPredicateT . const . const . return $ True+  never =+    filterPredicateT . const . const . return $ False+  f .&&. g =+    filterPredicateT $ \p k -> do r <- runFilterPredicateT f p k+                                  if r+                                    then+                                      runFilterPredicateT g p k+                                    else+                                      return False+  f .||. g =+    filterPredicateT $ \p k -> do r <- runFilterPredicateT f p k+                                  if r+                                    then+                                      return True+                                    else+                                      runFilterPredicateT g p k+  (.!.) f =+    filterPredicateT $ \p -> liftM not . runFilterPredicateT f p+  extension f = +    filterPredicateT $ const . return . f . P.takeExtension+  directory f = +    filterPredicateT $ const . return . f . P.takeDirectory+  hasExtension =+    filterPredicateT $ const . return . P.hasExtension+  splitExtension f =+    filterPredicateT $ const . return . uncurry f . P.splitExtension+  splitDirectories f = +    filterPredicateT $ const . return . f . P.splitDirectories+  hasTrailingPathSeparator =+    filterPredicateT $ const . return . P.hasTrailingPathSeparator+  fileName f = +    filterPredicateT $ const . return . f . P.takeFileName+  baseName f = +    filterPredicateT $ const . return . f . P.takeBaseName+  normalise f = +    filterPredicateT $ const . return . f . P.normalise+  makeValid f = +    filterPredicateT $ const . return . f . P.makeValid+  isRelative =+    filterPredicateT $ const . return . P.isRelative+  isAbsolute =+    filterPredicateT $ const . return . P.isAbsolute+  isValid =+    filterPredicateT $ const . return . P.isValid+
+ src/System/FilePath/FilePather/FileType.hs view
@@ -0,0 +1,11 @@+module System.FilePath.FilePather.FileType+(+  FileType(..)+) where+-- | The possible types of a file.+data FileType =+  File -- ^ The type is a normal file.+  | Directory -- ^ The type is a directory.+  | Unknown -- ^ The type is unknown.+  deriving (Eq, Show, Enum)+
+ src/System/FilePath/FilePather/FilterPredicate.hs view
@@ -0,0 +1,52 @@+module System.FilePath.FilePather.FilterPredicate+(+  FilterPredicateT+, FilterPredicate+, filterPredicateT+, filterPredicate+, runFilterPredicateT+, runFilterPredicate+) where++import Control.Monad.Identity+import System.FilePath.FilePather.FileType++newtype FilterPredicateT f =+  FilterPredicateT (FilePath -> FileType -> f Bool)++-- | A filter predicate that does not require effects to compute its result.+type FilterPredicate =+  FilterPredicateT Identity++-- | A filter predicate takes a 'FilePath' and a file type and returns whether or not to filter the value.+filterPredicateT ::+  (FilePath -> FileType -> f Bool)+  -> FilterPredicateT f+filterPredicateT =+  filterPredicateT++-- | Construct a filter predicate that does not require effects to compute its result.+filterPredicate ::+  (FilePath -> FileType -> Bool)+  -> FilterPredicate+filterPredicate f =+  filterPredicateT (\z -> Identity . f z)++-- | Extract the filter predicate function.+runFilterPredicateT ::+  FilterPredicateT f+  -> FilePath+  -> FileType+  -> f Bool+runFilterPredicateT (FilterPredicateT f) =+  f++-- | Construct a filter predicate that does not require effects to compute its result.+runFilterPredicate ::+  FilterPredicate+  -> FilePath+  -> FileType+  -> Bool+runFilterPredicate p k =+  runIdentity . runFilterPredicateT p k+
+ src/System/FilePath/FilePather/Find.hs view
@@ -0,0 +1,111 @@+module System.FilePath.FilePather.Find+(+  Find(..)+) where++import Control.Monad.Identity+import Control.Monad.Trans.Identity+import Control.Comonad+import System.FilePath.FilePather.RecursePredicate+import System.FilePath.FilePather.FilterPredicate+import System.FilePath.FilePather.FileType+import System.Directory++-- | Finds all files using the given recurse predicate and filter predicate in the given file path.+class Find f where+  find ::+    FilterPredicateT f+    -> RecursePredicateT f+    -> FilePath+    -> IO [FilePath]++instance Find Identity where+  find f' r' p = +    let f =+          runFilterPredicateT f'+        r =+          runRecursePredicateT r'+        keep ::+          Bool+          -> [FilePath]+          -> [FilePath]+        keep u =+          if u then (p:) else id+        rkeep :: +          [FilePath]+          -> Bool+          -> IO [FilePath]+        rkeep d u =+          return (keep u d)+        trkeep ::+          FileType+          -> IO [FilePath]+        trkeep t =+          rkeep [] $ runIdentity (f p t)+   in do fe <- doesFileExist p+         if fe+           then+             trkeep File+           else+             do de <- doesDirectoryExist p+                if de+                  then  +                    let (Identity k) = f p Directory+                        (Identity l) = r p+                    in if l+                         then+                           do t <- getDirectoryContents p+                              u <- liftM concat $ forM (filter (`notElem` [".", ".."]) t) (find f' r')+                              rkeep u k+                         else+                           rkeep [] k+                  else+                    trkeep Unknown++instance Find IO where+  find f' r' p =+    let f =+          runFilterPredicateT f'+        r =+          runRecursePredicateT r'+        keep ::+          Bool+          -> [FilePath]+          -> [FilePath]+        keep u =+          if u then (p:) else id+        rkeep :: +          [FilePath]+          -> Bool+          -> IO [FilePath]+        rkeep d u =+          return (keep u d)+        trkeep ::+          FileType+          -> IO [FilePath]+        trkeep t =+          f p t >>= rkeep []+    in do fe <- doesFileExist p+          if fe+            then+              trkeep File+            else+              do de <- doesDirectoryExist p+                 if de+                   then+                     do k <- f p Directory+                        l <- r p+                        if l+                          then+                            do t <- getDirectoryContents p+                               u <- liftM concat $ forM (filter (`notElem` [".", ".."]) t) (find f' r')+                               rkeep u k+                          else+                            rkeep [] k+                   else+                     trkeep Unknown++instance Comonad f => Find (IdentityT f) where+  find f r =+    find (filterPredicateT $ \p -> Identity . extract . runFilterPredicateT f p) (recursePredicateT $ Identity . extract . runRecursePredicateT r)+
+ src/System/FilePath/FilePather/RecursePredicate.hs view
@@ -0,0 +1,50 @@+module System.FilePath.FilePather.RecursePredicate+(+  RecursePredicateT+, RecursePredicate+, recursePredicateT+, recursePredicate+, runRecursePredicateT+, runRecursePredicate+) where++import Control.Monad.Identity++-- | A recurse predicate takes a 'FilePath' and returns whether or not to continue recursing on that file.+newtype RecursePredicateT f =+  RecursePredicateT (FilePath -> f Bool)++-- | A recurse predicate that does not require effects to compute its result.+type RecursePredicate =+  RecursePredicateT Identity++-- | Construct a recurse predicate. The most general construction function.+recursePredicateT ::+  (FilePath -> f Bool)+  -> RecursePredicateT f+recursePredicateT =+  RecursePredicateT++-- | Construct a recurse predicate that does not require effects to compute its result.+recursePredicate ::+  (FilePath -> Bool)+  -> RecursePredicate+recursePredicate f =+  recursePredicateT (Identity . f)++-- | Extract the recurse predicate function.+runRecursePredicateT ::+  RecursePredicateT f+  -> FilePath+  -> f Bool+runRecursePredicateT (RecursePredicateT f) =+  f++-- | Extract the recurse predicate function that does not require effects to compute its result.+runRecursePredicate ::+  RecursePredicate+  -> FilePath+  -> Bool+runRecursePredicate p =+  runIdentity . runRecursePredicateT p+