diff --git a/Common.hs b/Common.hs index a3802da5f2..7e8dd9a2a5 100644 --- a/Common.hs +++ b/Common.hs @@ -24,3 +24,4 @@ import Utility.Conditional as X import Utility.SafeCommand as X import Utility.Path as X import Utility.Directory as X +import Utility.Monad as X diff --git a/Locations.hs b/Locations.hs index 1179886ade..3843495f9c 100644 --- a/Locations.hs +++ b/Locations.hs @@ -89,11 +89,7 @@ gitAnnexLocation key r annexLocation key hashDirMixed where go dir locs = fromMaybe (dir head locs) <$> check dir locs - check _ [] = return Nothing - check dir (l:ls) = do - let f = dir l - e <- doesFileExist f - if e then return (Just f) else check dir ls + check dir = firstM $ \f -> doesFileExist $ dir f {- The annex directory of a repository. -} gitAnnexDir :: Git.Repo -> FilePath diff --git a/Remote/Web.hs b/Remote/Web.hs index 5871ae8dae..d5acd7d862 100644 --- a/Remote/Web.hs +++ b/Remote/Web.hs @@ -13,7 +13,6 @@ import qualified Git import Config import Logs.Web import qualified Utility.Url as Url -import Utility.Monad remote :: RemoteType Annex remote = RemoteType { diff --git a/Utility/Conditional.hs b/Utility/Conditional.hs index 7a0df4b482..85e39ec64c 100644 --- a/Utility/Conditional.hs +++ b/Utility/Conditional.hs @@ -9,12 +9,6 @@ module Utility.Conditional where import Control.Monad (when, unless) -untilTrue :: Monad m => [v] -> (v -> m Bool) -> m Bool -untilTrue [] _ = return False -untilTrue (v:vs) a = do - ok <- a v - if ok then return ok else untilTrue vs a - whenM :: Monad m => m Bool -> m () -> m () whenM c a = c >>= flip when a diff --git a/Utility/Monad.hs b/Utility/Monad.hs index 9523e17165..0d1675fa49 100644 --- a/Utility/Monad.hs +++ b/Utility/Monad.hs @@ -24,3 +24,7 @@ firstM p (x:xs) = do - stopping once one is found. -} anyM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool anyM p = liftM isJust . firstM p + +{- Runs an action on values from a list until it succeeds. -} +untilTrue :: (Monad m) => [a] -> (a -> m Bool) -> m Bool +untilTrue = flip anyM