LIB: use whenM/unlessM
This commit is contained in:
parent
ffe8037160
commit
0f1c8dafe8
@ -16,6 +16,7 @@ import Data.List
|
||||
isPrefixOf
|
||||
)
|
||||
import Data.Typeable
|
||||
import IO.Utils
|
||||
import System.Directory
|
||||
(
|
||||
doesDirectoryExist
|
||||
@ -46,17 +47,13 @@ instance Exception FmIOException
|
||||
-- Throws an exception if the filepath is not absolute
|
||||
-- or the file does not exist.
|
||||
fileSanityThrow :: FilePath -> IO ()
|
||||
fileSanityThrow fp = do
|
||||
throwNotAbsolute fp
|
||||
throwFileDoesNotExist fp
|
||||
fileSanityThrow fp = throwNotAbsolute fp >> throwFileDoesNotExist fp
|
||||
|
||||
|
||||
-- Throws an exception if the filepath is not absolute
|
||||
-- or the dir does not exist.
|
||||
dirSanityThrow :: FilePath -> IO ()
|
||||
dirSanityThrow fp = do
|
||||
throwNotAbsolute fp
|
||||
throwDirDoesNotExist fp
|
||||
dirSanityThrow fp = throwNotAbsolute fp >> throwDirDoesNotExist fp
|
||||
|
||||
|
||||
throwNotAbsolute :: FilePath -> IO ()
|
||||
@ -64,21 +61,18 @@ throwNotAbsolute fp = unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
||||
|
||||
|
||||
throwDirDoesExist :: FilePath -> IO ()
|
||||
throwDirDoesExist fp = do
|
||||
exists <- doesDirectoryExist fp
|
||||
when exists (throw $ DirDoesExist fp)
|
||||
throwDirDoesExist fp =
|
||||
whenM (doesDirectoryExist fp) (throw $ DirDoesExist fp)
|
||||
|
||||
|
||||
throwDirDoesNotExist :: FilePath -> IO ()
|
||||
throwDirDoesNotExist fp = do
|
||||
exists <- doesDirectoryExist fp
|
||||
unless exists (throw $ FileDoesNotExist fp)
|
||||
throwDirDoesNotExist fp =
|
||||
unlessM (doesDirectoryExist fp) (throw $ FileDoesNotExist fp)
|
||||
|
||||
|
||||
throwFileDoesNotExist :: FilePath -> IO ()
|
||||
throwFileDoesNotExist fp = do
|
||||
exists <- doesFileExist fp
|
||||
unless exists (throw $ FileDoesNotExist fp)
|
||||
throwFileDoesNotExist fp =
|
||||
unlessM (doesFileExist fp) (throw $ FileDoesNotExist fp)
|
||||
|
||||
|
||||
throwSameFile :: FilePath -- ^ should be canonicalized
|
||||
|
@ -11,7 +11,6 @@ import Control.Monad
|
||||
(
|
||||
unless
|
||||
, void
|
||||
, when
|
||||
)
|
||||
import Data.DirTree
|
||||
import Data.DirTree.Zipper
|
||||
|
@ -16,6 +16,7 @@ import Control.Concurrent.STM.TVar
|
||||
import Control.Monad
|
||||
(
|
||||
when
|
||||
, unless
|
||||
)
|
||||
|
||||
|
||||
@ -29,3 +30,7 @@ modifyTVarIO tvar f = atomically $ modifyTVar tvar f
|
||||
|
||||
whenM :: Monad m => m Bool -> m () -> m ()
|
||||
whenM mb a = mb >>= (`when` a)
|
||||
|
||||
|
||||
unlessM :: Monad m => m Bool -> m () -> m ()
|
||||
unlessM mb a = mb >>= (`unless` a)
|
||||
|
Loading…
Reference in New Issue
Block a user