implemented playerSearch

This commit is contained in:
Jonathan Lamothe
2019-09-18 01:55:38 -04:00
parent 2ff8cff1c8
commit ed9e437a1a
2 changed files with 34 additions and 1 deletions

View File

@@ -120,7 +120,8 @@ module Mtlstats.Types (
gmsPoints,
addGameStats,
-- ** Player Helpers
pPoints
pPoints,
playerSearch
) where
import Control.Monad.Trans.State (StateT)
@@ -136,6 +137,7 @@ import Data.Aeson
, (.:)
, (.=)
)
import Data.List (isInfixOf)
import Lens.Micro (Lens', lens, (&), (^.), (.~))
import Lens.Micro.TH (makeLenses)
import qualified UI.NCurses as C
@@ -636,3 +638,16 @@ addGameStats s1 s2 = GameStats
-- | Calculates a player's points
pPoints :: PlayerStats -> Int
pPoints s = s^.psGoals + s^.psAssists
-- | Searches through a list of players
playerSearch
:: String
-- ^ The search string
-> [Player]
-- ^ The list of players to search
-> [(Int, Player)]
-- ^ The matching players with their index numbers
playerSearch sStr =
filter (match sStr) .
zip [0..]
where match sStr (_, p) = sStr `isInfixOf` (p^.pName)