diff options
author | Joey Hess <joey@kitenet.net> | 2011-12-03 09:10:23 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-12-03 09:10:23 -0400 |
commit | 64672c6262048e9498be667f8dc7460c0a9189e2 (patch) | |
tree | 194453dc8731dff8207bbc76bc752ad472c1f795 | |
parent | b5930f6d076d266b337b415447f448fbb14d9ea3 (diff) |
refactor
-rw-r--r-- | Common.hs | 1 | ||||
-rw-r--r-- | Locations.hs | 6 | ||||
-rw-r--r-- | Remote/Web.hs | 1 | ||||
-rw-r--r-- | Utility/Conditional.hs | 6 | ||||
-rw-r--r-- | Utility/Monad.hs | 4 |
5 files changed, 6 insertions, 12 deletions
@@ -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 1179886ad..3843495f9 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 5871ae8da..d5acd7d86 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 7a0df4b48..85e39ec64 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 9523e1716..0d1675fa4 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 |