From b9d8b263df7bb71c835ffc12038d0b5537d103bf Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Thu, 13 Feb 2020 01:39:56 -0500 Subject: [PATCH] implemented posCallback --- src/Mtlstats/Helpers/Position.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Mtlstats/Helpers/Position.hs b/src/Mtlstats/Helpers/Position.hs index 6b6b93c..2c4c0fe 100644 --- a/src/Mtlstats/Helpers/Position.hs +++ b/src/Mtlstats/Helpers/Position.hs @@ -19,6 +19,8 @@ along with this program. If not, see . -} +{-# LANGUAGE LambdaCase #-} + module Mtlstats.Helpers.Position ( posSearch , posSearchExact @@ -26,12 +28,15 @@ module Mtlstats.Helpers.Position , getPositions ) where +import Control.Monad.Trans.State (gets) import Data.Char (toUpper) import Data.List (isInfixOf) +import Data.Maybe (fromMaybe) import qualified Data.Set as S -import Lens.Micro ((^.)) +import Lens.Micro ((^.), to) import Mtlstats.Types +import Mtlstats.Util -- | Searches the 'Database' for all the positions used posSearch @@ -70,7 +75,12 @@ posCallback -- ^ The index number of the position selected or 'Nothing' if blank -> Action () -- ^ The action to perform -posCallback = undefined +posCallback callback = \case + Nothing -> callback "" + Just n -> do + ps <- gets (^.database.to getPositions) + let pos = fromMaybe "" $ nth n ps + callback pos -- | Extracts a list of positions from a 'Database' getPositions :: Database -> [String]