From 9ee33cbd033a07d26cc0870812e04d07bdbe5d14 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 5 Mar 2020 05:15:58 -0500 Subject: [PATCH] hlint suggestions --- src/Mtlstats/Actions/NewGame.hs | 14 ++++++++------ src/Mtlstats/Menu.hs | 9 +++++---- src/Mtlstats/Prompt.hs | 4 +--- src/Mtlstats/Report.hs | 6 ++---- src/Mtlstats/Types.hs | 5 ++--- src/Mtlstats/Util.hs | 5 +++-- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Mtlstats/Actions/NewGame.hs b/src/Mtlstats/Actions/NewGame.hs index bc6d666..ddc20eb 100644 --- a/src/Mtlstats/Actions/NewGame.hs +++ b/src/Mtlstats/Actions/NewGame.hs @@ -124,12 +124,13 @@ awardGoal n ps = ps (\m -> let stats = M.findWithDefault newPlayerStats n m in M.insert n (stats & psGoals %~ succ) m) - & database.dbPlayers %~ map - (\(i, p) -> if i == n + & database.dbPlayers %~ zipWith + (\i p -> if i == n then p & pYtd.psGoals %~ succ & pLifetime.psGoals %~ succ - else p) . zip [0..] + else p) + [0..] -- | Awards an assist to a player awardAssist @@ -142,12 +143,13 @@ awardAssist n ps = ps (\m -> let stats = M.findWithDefault newPlayerStats n m in M.insert n (stats & psAssists %~ succ) m) - & database.dbPlayers %~ map - (\(i, p) -> if i == n + & database.dbPlayers %~ zipWith + (\i p -> if i == n then p & pYtd.psAssists %~ succ & pLifetime.psAssists %~ succ - else p) . zip [0..] + else p) + [0..] -- | Resets the entered data for the current goal resetGoalData :: ProgState -> ProgState diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 4e4db16..7b298d6 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -170,10 +170,11 @@ gameGoalieMenu s = let goalie <- nth n $ s^.database.dbGoalies Just (n, goalie)) gids - in Menu title () $ map - (\(ch, (gid, goalie)) -> MenuItem ch (goalieSummary goalie) $ - modify $ GI.setGameGoalie gid) $ - zip ['1'..] goalies + in Menu title () $ zipWith + (\ch (gid, goalie) -> MenuItem ch (goalieSummary goalie) $ + modify $ GI.setGameGoalie gid) + ['1'..] + goalies -- | The edit menu editMenu :: Menu () diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index 8f6d12d..e250178 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -164,9 +164,7 @@ numPromptWithFallback pStr fallback act = Prompt , promptProcessChar = \ch str -> if isDigit ch then str ++ [ch] else str - , promptAction = \inStr -> case readMaybe inStr of - Nothing -> fallback - Just n -> act n + , promptAction = maybe fallback act . readMaybe , promptSpecialKey = const $ return () } diff --git a/src/Mtlstats/Report.hs b/src/Mtlstats/Report.hs index f9b5ad4..7385adc 100644 --- a/src/Mtlstats/Report.hs +++ b/src/Mtlstats/Report.hs @@ -241,8 +241,7 @@ filteredPlayerReport width label criteria showTotals lineNumbers ps = let else repeat "" table = overlayLast olayText - $ map (\(ln, line) -> overlay ln $ centre width line) - $ zip lnOverlay + $ zipWith (\ln line -> overlay ln $ centre width line) lnOverlay $ complexTable ([right, left] ++ repeat right) $ tHeader : body ++ if showTotals then [separator, totals] @@ -301,8 +300,7 @@ goalieReport width showTotals lineNumbers goalieData = let then "" : [right 2 $ show x | x <- [(1 :: Int)..]] else repeat "" - in map (\(ln, line) -> overlay ln $ centre width line) - $ zip lnOverlay + in zipWith (\ln line -> overlay ln $ centre width line) lnOverlay $ overlayLast olayText $ complexTable ([right, left] ++ repeat right) $ header : body ++ if showTotals diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index 7b2cd69..f3e37a5 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -208,9 +208,8 @@ import Data.Aeson , (.=) ) import Data.Char (toUpper) -import Data.List (isInfixOf) +import Data.List (find, isInfixOf) import qualified Data.Map as M -import Data.Maybe (listToMaybe) import Lens.Micro (Lens', lens, (&), (^.), (.~)) import Lens.Micro.TH (makeLenses) import qualified UI.NCurses as C @@ -1019,7 +1018,7 @@ playerSearchExact -> Maybe (Int, Player) -- ^ The player's index and value playerSearchExact sStr = - listToMaybe . filter match . zip [0..] + find match . zip [0..] where match (_, p) = p^.pName == sStr -- | Modifies a player with a given name diff --git a/src/Mtlstats/Util.hs b/src/Mtlstats/Util.hs index 153f719..951859c 100644 --- a/src/Mtlstats/Util.hs +++ b/src/Mtlstats/Util.hs @@ -52,8 +52,9 @@ modifyNth -> [a] -- ^ The list -> [a] -modifyNth n f = map (\(i, x) -> if i == n then f x else x) - . zip [0..] +modifyNth n f = zipWith + (\i x -> if i == n then f x else x) + [0..] -- | Modify a value indexed by a given key in a map using a default -- initial value if not present