From 678726c10c13481c082743808a5188d28567e2b3 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 25 Aug 2011 00:28:55 -0400 Subject: code simplification thanks to applicative functors --- Remote.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'Remote.hs') diff --git a/Remote.hs b/Remote.hs index 1a5006f6f..2c883f1a8 100644 --- a/Remote.hs +++ b/Remote.hs @@ -29,11 +29,12 @@ module Remote ( forceTrust ) where -import Control.Monad (filterM, liftM2) +import Control.Monad (filterM) import Data.List import qualified Data.Map as M import Data.String.Utils import Data.Maybe +import Control.Applicative import Types import Types.Remote @@ -111,10 +112,10 @@ nameToUUID "." = getUUID =<< Annex.gitRepo -- special case for current repo nameToUUID n = do res <- byName' n case res of - Left e -> return . fromMaybe (error e) =<< byDescription + Left e -> fromMaybe (error e) <$> byDescription Right r -> return $ uuid r where - byDescription = return . M.lookup n . invertMap =<< uuidMap + byDescription = M.lookup n . invertMap <$> uuidMap invertMap = M.fromList . map swap . M.toList swap (a, b) = (b, a) @@ -124,10 +125,10 @@ prettyPrintUUIDs uuids = do here <- getUUID =<< Annex.gitRepo -- Show descriptions from the uuid log, falling back to remote names, -- as some remotes may not be in the uuid log - m <- liftM2 M.union uuidMap $ - return . M.fromList . map (\r -> (uuid r, name r)) =<< genList + m <- M.union <$> uuidMap <*> availMap return $ unwords $ map (\u -> "\t" ++ prettify m u here ++ "\n") uuids where + availMap = M.fromList . map (\r -> (uuid r, name r)) <$> genList prettify m u here = base ++ ishere where base = if not $ null $ findlog m u @@ -147,7 +148,7 @@ remotesWithoutUUID rs us = filter (\r -> uuid r `notElem` us) rs {- Cost ordered lists of remotes that the LocationLog indicate may have a key. -} keyPossibilities :: Key -> Annex [Remote Annex] -keyPossibilities key = return . fst =<< keyPossibilities' False key +keyPossibilities key = fst <$> keyPossibilities' False key {- Cost ordered lists of remotes that the LocationLog indicate may have a key. - -- cgit v1.2.3