From e6e89d68fdda2fb1f8f7ec2e4485ab7a5584db15 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sat, 1 Feb 2020 22:50:20 -0500 Subject: [PATCH] Use list comprehensions instead of clunky combinations of map and filter --- src/ShellCheck/Checks/Commands.hs | 6 +++--- src/ShellCheck/Fixer.hs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index 7841089..21c6cb7 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -706,7 +706,7 @@ checkReadExpansions = CommandCheck (Exactly "read") check options = getGnuOpts flagsForRead getVars cmd = fromMaybe [] $ do opts <- options cmd - return . map snd $ filter (\(x,_) -> x == "" || x == "a") opts + return [y | (x,y) <- opts, x == "" || x == "a"] check cmd = mapM_ warning $ getVars cmd warning t = potentially $ do @@ -995,7 +995,7 @@ missingDestination handler token = do _ -> return () where args = getAllFlags token - params = map fst $ filter (\(_,x) -> x == "") args + params = [x | (x,"") <- args] hasTarget = any (\(_,x) -> x /= "" && x `isPrefixOf` "target-directory") args @@ -1083,7 +1083,7 @@ checkSudoArgs = CommandCheck (Basename "sudo") f where f t = potentially $ do opts <- parseOpts t - let nonFlags = map snd $ filter (\(flag, _) -> flag == "") opts + let nonFlags = [x | ("",x) <- opts] commandArg <- nonFlags !!! 0 command <- getLiteralString commandArg guard $ command `elem` builtins diff --git a/src/ShellCheck/Fixer.hs b/src/ShellCheck/Fixer.hs index 12de3c2..a69616e 100644 --- a/src/ShellCheck/Fixer.hs +++ b/src/ShellCheck/Fixer.hs @@ -295,7 +295,7 @@ prop_pstreeSumsCorrectly kvs targets = -- Trivial O(n * m) implementation dumbPrefixSums :: [(Int, Int)] -> [Int] -> [Int] dumbPrefixSums kvs targets = - let prefixSum target = sum . map snd . filter (\(k,v) -> k <= target) $ kvs + let prefixSum target = sum [v | (k,v) <- kvs, k <= target] in map prefixSum targets -- PSTree O(n * log m) implementation smartPrefixSums :: [(Int, Int)] -> [Int] -> [Int]