make gameWon and gameTied return Maybe Bool instead of Bool
This commit is contained in:
@@ -30,6 +30,7 @@ module Mtlstats.Actions
|
||||
, overtimeCheck
|
||||
) where
|
||||
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Lens.Micro (over, (^.), (&), (.~), (?~), (%~))
|
||||
|
||||
import Mtlstats.Types
|
||||
@@ -63,10 +64,10 @@ removeChar = inputBuffer %~ \case
|
||||
-- | Determines whether or not to perform a check for overtime
|
||||
overtimeCheck :: ProgState -> ProgState
|
||||
overtimeCheck s
|
||||
| gameTied (s^.progMode.gameStateL) =
|
||||
| fromMaybe False $ gameTied $ s^.progMode.gameStateL =
|
||||
s & progMode.gameStateL
|
||||
%~ (homeScore .~ Nothing)
|
||||
. (awayScore .~ Nothing)
|
||||
| gameWon (s^.progMode.gameStateL) =
|
||||
| fromMaybe False $ gameWon $ s^.progMode.gameStateL =
|
||||
s & progMode.gameStateL.overtimeFlag ?~ False
|
||||
| otherwise = s
|
||||
|
||||
@@ -493,17 +493,13 @@ otherScore s = case s ^. gameType of
|
||||
Just AwayGame -> s ^. homeScore
|
||||
Nothing -> Nothing
|
||||
|
||||
-- | Checks if the game was won (returns 'False' if unknown)
|
||||
gameWon :: GameState -> Bool
|
||||
gameWon gs = case (,) <$> teamScore gs <*> otherScore gs of
|
||||
Just (team, other) -> team > other
|
||||
Nothing -> False
|
||||
-- | Checks if the game was won
|
||||
gameWon :: GameState -> Maybe Bool
|
||||
gameWon gs = (>) <$> teamScore gs <*> otherScore gs
|
||||
|
||||
-- | Checks if the game has tied (retuns 'False' if unknown)
|
||||
gameTied :: GameState -> Bool
|
||||
gameTied gs = case (,) <$> gs^.homeScore <*> gs^.awayScore of
|
||||
Just (home, away) -> home == away
|
||||
Nothing -> False
|
||||
-- | Checks if the game has tied
|
||||
gameTied :: GameState -> Maybe Bool
|
||||
gameTied gs = (==) <$> gs^.homeScore <*> gs^.awayScore
|
||||
|
||||
-- | Calculates a player's points
|
||||
pPoints :: PlayerStats -> Int
|
||||
|
||||
Reference in New Issue
Block a user