From 2854c544747f1604db3dacd647d3579b3c8907d8 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 28 Aug 2019 01:09:03 -0400 Subject: [PATCH] removed unnecessary lenses --- src/Mtlstats/Menu.hs | 4 ++-- src/Mtlstats/Prompt.hs | 6 ++--- src/Mtlstats/Types.hs | 40 --------------------------------- test/TypesSpec.hs | 51 ------------------------------------------ 4 files changed, 5 insertions(+), 96 deletions(-) diff --git a/src/Mtlstats/Menu.hs b/src/Mtlstats/Menu.hs index 7385909..4574e7a 100644 --- a/src/Mtlstats/Menu.hs +++ b/src/Mtlstats/Menu.hs @@ -75,7 +75,7 @@ newSeasonMenu = Menu "*** SEASON TYPE ***" () gameTypeMenu :: Menu () gameTypeMenu = Menu "*** GAME TYPE ***" () [ MenuItem '1' "Home Game" $ - modify $ progMode . gameTypeL ?~ HomeGame + modify $ progMode . gameStateL . gameType ?~ HomeGame , MenuItem '2' "Away Game" $ - modify $ progMode . gameTypeL ?~ AwayGame + modify $ progMode . gameStateL . gameType ?~ AwayGame ] diff --git a/src/Mtlstats/Prompt.hs b/src/Mtlstats/Prompt.hs index e979ceb..80cd7d8 100644 --- a/src/Mtlstats/Prompt.hs +++ b/src/Mtlstats/Prompt.hs @@ -95,15 +95,15 @@ numPrompt pStr act = Prompt otherTeamPrompt :: Prompt otherTeamPrompt = strPrompt "Other team: " $ - modify . (progMode . otherTeamL .~) + modify . (progMode . gameStateL . otherTeam .~) homeScorePrompt :: Prompt homeScorePrompt = numPrompt "Home score: " $ - modify . (progMode . homeScoreL ?~) + modify . (progMode . gameStateL . homeScore ?~) awayScorePrompt :: Prompt awayScorePrompt = numPrompt "Away score: " $ - modify . (progMode . awayScoreL ?~) + modify . (progMode . gameStateL . awayScore ?~) drawSimplePrompt :: String -> ProgState -> C.Update () drawSimplePrompt pStr s = C.drawString $ pStr ++ s ^. inputBuffer diff --git a/src/Mtlstats/Types.hs b/src/Mtlstats/Types.hs index beeee04..d333719 100644 --- a/src/Mtlstats/Types.hs +++ b/src/Mtlstats/Types.hs @@ -42,10 +42,6 @@ module Mtlstats.Types ( inputBuffer, -- ** ProgMode Lenses gameStateL, - gameTypeL, - otherTeamL, - homeScoreL, - awayScoreL, -- ** GameState Lenses gameType, otherTeam, @@ -391,42 +387,6 @@ gameStateL = lens _ -> newGameState) (\_ gs -> NewGame gs) -gameTypeL :: Lens' ProgMode (Maybe GameType) -gameTypeL = lens - (\case - NewGame gs -> gs ^. gameType - _ -> Nothing) - (\m gt -> case m of - NewGame gs -> NewGame $ gs & gameType .~ gt - _ -> NewGame $ newGameState & gameType .~ gt) - -otherTeamL :: Lens' ProgMode String -otherTeamL = lens - (\case - NewGame gs -> gs ^. otherTeam - _ -> "") - (\m ot -> case m of - NewGame gs -> NewGame $ gs & otherTeam .~ ot - _ -> NewGame $ newGameState & otherTeam .~ ot) - -homeScoreL :: Lens' ProgMode (Maybe Int) -homeScoreL = lens - (\case - NewGame gs -> gs ^. homeScore - _ -> Nothing) - (\m hs -> case m of - NewGame gs -> NewGame $ gs & homeScore .~ hs - _ -> NewGame $ newGameState & homeScore .~ hs) - -awayScoreL :: Lens' ProgMode (Maybe Int) -awayScoreL = lens - (\case - NewGame gs -> gs ^. awayScore - _ -> Nothing) - (\m as -> case m of - NewGame gs -> NewGame $ gs & awayScore .~ as - _ -> NewGame $ newGameState & awayScore .~ as) - -- | Constructor for a 'ProgState' newProgState :: ProgState newProgState = ProgState diff --git a/test/TypesSpec.hs b/test/TypesSpec.hs index 04cdeca..8c03628 100644 --- a/test/TypesSpec.hs +++ b/test/TypesSpec.hs @@ -42,10 +42,6 @@ spec = describe "Mtlstats.Types" $ do databaseSpec pPointsSpec gameStateLSpec - gameTypeLSpec - otherTeamLSpec - homeScoreLSpec - awayScoreLSpec teamScoreSpec otherScoreSpec Menu.spec @@ -94,53 +90,6 @@ gameStateLSpec = describe "gameStateL" $ lensSpec gameStateL ] where gs t = newGameState & gameType ?~ t -gameTypeLSpec :: Spec -gameTypeLSpec = describe "gameTypeL" $ lensSpec gameTypeL - [ ( MainMenu, Nothing ) - , ( m HomeGame, Just HomeGame ) - , ( m AwayGame, Just AwayGame ) - ] - [ ( MainMenu, Just HomeGame ) - , ( MainMenu, Just AwayGame ) - , ( m HomeGame, Just AwayGame ) - , ( m AwayGame, Just HomeGame ) - , ( m HomeGame, Nothing ) - ] - where m t = NewGame $ newGameState & gameType ?~ t - -otherTeamLSpec :: Spec -otherTeamLSpec = describe "otherTeamL" $ lensSpec otherTeamL - [ ( MainMenu, "" ) - , ( m "foo", "foo" ) - ] - [ ( MainMenu, "foo" ) - , ( m "foo", "bar" ) - , ( m "foo", "" ) - ] - where m t = NewGame $ newGameState & otherTeam .~ t - -homeScoreLSpec :: Spec -homeScoreLSpec = describe "homeScoreL" $ lensSpec homeScoreL - [ ( MainMenu, Nothing ) - , ( m 1, Just 1 ) - ] - [ ( MainMenu, Just 1 ) - , ( m 1, Just 2 ) - , ( m 1, Nothing ) - ] - where m s = NewGame $ newGameState & homeScore ?~ s - -awayScoreLSpec :: Spec -awayScoreLSpec = describe "awayScoreL" $ lensSpec awayScoreL - [ ( MainMenu, Nothing ) - , ( m 1, Just 1 ) - ] - [ ( MainMenu, Just 1 ) - , ( m 1, Just 2 ) - , ( m 1, Nothing ) - ] - where m s = NewGame $ newGameState & awayScore ?~ s - teamScoreSpec :: Spec teamScoreSpec = describe "teamScore" $ do let