Add lsif. Fixes #39

This commit is contained in:
Gabriel Gonzalez 2015-08-22 12:54:34 -07:00
parent b824122bcf
commit 8f4a39256f

View file

@ -165,6 +165,7 @@ module Turtle.Prelude (
, stderr , stderr
, strict , strict
, ls , ls
, lsif
, lstree , lstree
, cat , cat
, grep , grep
@ -596,6 +597,24 @@ lstree path = do
then return child <|> lstree child then return child <|> lstree child
else return child else return child
{-| Stream all recursive descendents of the given directory
This skips any directories that fail the supplied predicate
> lstree = lsif (\_ -> return True)
-}
lsif :: (FilePath -> IO Bool) -> FilePath -> Shell FilePath
lsif pred path = do
child <- ls path
isDir <- liftIO (testdir child)
if isDir
then do
continue <- liftIO (pred child)
if continue
then return child <|> lsif pred child
else return child
else return child
-- | Move a file or directory -- | Move a file or directory
mv :: MonadIO io => FilePath -> FilePath -> io () mv :: MonadIO io => FilePath -> FilePath -> io ()
mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath) mv oldPath newPath = liftIO (Filesystem.rename oldPath newPath)