packages feed

FilePather 0.1.5 → 0.1.6

raw patch · 5 files changed

+136/−94 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- System.FilePath.FilePather.FileType: isDirectoryType :: FileType -> Bool
- System.FilePath.FilePather.FileType: isFileType :: FileType -> Bool
- System.FilePath.FilePather.FileType: isUnknownType :: FileType -> Bool
+ System.FilePath.FilePather.FileType: isDirectory :: FileType -> Bool
+ System.FilePath.FilePather.FileType: isFile :: FileType -> Bool
+ System.FilePath.FilePather.FileType: isUnknown :: FileType -> Bool
+ System.FilePath.FilePather.FilterPredicate: isDirectoryType :: Monad f => FilterPredicateT f
+ System.FilePath.FilePather.FilterPredicate: isFileType :: Monad f => FilterPredicateT f
+ System.FilePath.FilePather.FilterPredicate: isUnknownType :: Monad f => FilterPredicateT f
+ System.FilePath.FilePather.Find: findi :: FilterPredicate -> RecursePredicate -> FilePath -> IO [FilePath]

Files

FilePather.cabal view
@@ -1,5 +1,5 @@ Name:               FilePather-Version:            0.1.5+Version:            0.1.6 Author:             Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> Maintainer:         Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> Copyright:          Tony Morris
src/System/FilePath/FilePather/FilePathPredicate.hs view
@@ -55,7 +55,7 @@     Monad g =>     (FilePath -> Bool)     -> f g-  -- | A predicate that computes its result based equivalence to a file name extension.+  -- | A predicate that computes its result based equivalence to a file name extension. This function matches with and without the preceding extension separator (.).   extensionEq ::     Monad g =>     FilePath@@ -194,7 +194,7 @@   (.!.) f =     recursePredicateT $ liftM not . runRecursePredicateT f   extension f = -    recursePredicateT $ return . f . P.takeExtension+    recursePredicateT $ return . liftM2 (||) f (f . drop 1) . P.takeExtension   directory f =      recursePredicateT $ return . f . P.takeDirectory   hasExtension =@@ -242,7 +242,7 @@   (.!.) f =     filterPredicateT $ \p -> liftM not . runFilterPredicateT f p   extension f = -    filterPredicateT $ const . return . f . P.takeExtension+    filterPredicateT $ const . return . liftM2 (||) f (f . drop 1) . P.takeExtension   directory f =      filterPredicateT $ const . return . f . P.takeDirectory   hasExtension =
src/System/FilePath/FilePather/FileType.hs view
@@ -1,9 +1,9 @@ module System.FilePath.FilePather.FileType (   FileType(..)-, isFileType-, isDirectoryType-, isUnknownType+, isFile+, isDirectory+, isUnknown ) where -- | The possible types of a file. data FileType =@@ -12,21 +12,21 @@   | Unknown -- ^ The type is unknown.   deriving (Eq, Show, Enum) -isFileType ::+isFile ::   FileType   -> Bool-isFileType =+isFile =   (==) File -isDirectoryType ::+isDirectory ::   FileType   -> Bool-isDirectoryType =+isDirectory =   (==) Directory -isUnknownType ::+isUnknown ::   FileType   -> Bool-isUnknownType =+isUnknown =   (==) Unknown 
src/System/FilePath/FilePather/FilterPredicate.hs view
@@ -8,6 +8,9 @@ , filterPredicate' , runFilterPredicateT , runFilterPredicate+, isDirectoryType+, isFileType+, isUnknownType ) where  import Control.Monad.Identity@@ -66,3 +69,20 @@ runFilterPredicate p k =   runIdentity . runFilterPredicateT p k +isDirectoryType ::+  Monad f =>+  FilterPredicateT f+isDirectoryType =+  filterPredicateT . const $ return . isDirectory++isFileType ::+  Monad f =>+  FilterPredicateT f+isFileType =+  filterPredicateT . const $ return . isFile++isUnknownType ::+  Monad f =>+  FilterPredicateT f+isUnknownType =+  filterPredicateT . const $ return . isUnknown
src/System/FilePath/FilePather/Find.hs view
@@ -1,11 +1,13 @@ module System.FilePath.FilePather.Find (   Find(..)+, findi ) where  import Control.Monad.Identity import Control.Monad.Trans.Identity import Control.Comonad+import System.FilePath import System.FilePath.FilePather.RecursePredicate import System.FilePath.FilePather.FilterPredicate import System.FilePath.FilePather.FileType@@ -27,92 +29,112 @@     getCurrentDirectory >>= find f r  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 ::          -          Bool-          -> [FilePath]-          -> IO [FilePath]-        rkeep u d =-          return (keep u d)-        trkeep ::-          FileType-          -> IO [FilePath]-        trkeep =-          flip rkeep [] . runIdentity . f p-   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+  find f' r' =+    let find' base p =+          let f =+                runFilterPredicateT f'+              r =+                runRecursePredicateT r'+              z ::+                FilePath+              z =+                if null base then p else base </> p+              keep ::+                Bool+                -> [FilePath]+                -> [FilePath]+              keep u =+                if u then (z:) else id+              rkeep ::+                Bool+                -> [FilePath]+                -> IO [FilePath]+              rkeep u d =+                return (keep u d)+              trkeep ::+                FileType+                -> IO [FilePath]+              trkeep =+                flip rkeep [] . runIdentity . f z+          in do fe <- doesFileExist z+                if fe+                  then+                    trkeep File+                  else+                    do de <- doesDirectoryExist z+                       if de                          then-                           do t <- getDirectoryContents p-                              u <- forM (filter (`notElem` [".", ".."]) t) (find f' r')-                              rkeep k (concat u)+                           let (Identity k) = f z Directory+                               (Identity l) = r z+                           in if l+                                then+                                  do t <- getDirectoryContents z+                                     u <- forM (filter (`notElem` [".", ".."]) t) (find f' r' . (z </>))+                                     rkeep k (concat u)+                                else+                                  rkeep k []                          else-                           rkeep k []-                  else-                    trkeep Unknown+                           trkeep Unknown+    in find' [] +-- | A specialisation of `find` to the `Identity` monad. Useful in assisting type-inference.+findi ::+  FilterPredicate+  -> RecursePredicate+  -> FilePath+  -> IO [FilePath]+findi =+  find+ 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 :: -          Bool-          -> [FilePath]-          -> IO [FilePath]-        rkeep u d =-          return (keep u d)-        trkeep ::-          FileType-          -> IO [FilePath]-        trkeep t =-          f p t >>= flip 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 <- forM (filter (`notElem` [".", ".."]) t) (find f' r')-                               rkeep k (concat u)-                          else-                            rkeep k []-                   else-                     trkeep Unknown+  find f' r' =+    let find' base p =+          let f =+                runFilterPredicateT f'+              r =+                runRecursePredicateT r'+              z ::+                FilePath+              z =+                if null base then p else base </> p+              keep ::+                Bool+                -> [FilePath]+                -> [FilePath]+              keep u =+                if u then (z:) else id+              rkeep ::+                Bool+                -> [FilePath]+                -> IO [FilePath]+              rkeep u d =+                return (keep u d)+              trkeep ::+                FileType+                -> IO [FilePath]+              trkeep t =+                f z t >>= flip rkeep []+          in do fe <- doesFileExist z+                if fe+                  then+                    trkeep File+                  else+                    do de <- doesDirectoryExist z+                       if de+                         then+                           do k <- f z Directory+                              l <- r z+                              if l+                                then+                                  do t <- getDirectoryContents z+                                     u <- forM (filter (`notElem` [".", ".."]) t) (find f' r' . (z </>))+                                     rkeep k (concat u)+                                else+                                  rkeep k []+                         else+                           trkeep Unknown+    in find' []  instance Comonad f => Find (IdentityT f) where   find f r =     find (filterPredicateT $ \p -> Identity . extract . runFilterPredicateT f p) (recursePredicateT $ Identity . extract . runRecursePredicateT r)-