Skip to content

Commit

Permalink
Use enumerate
Browse files Browse the repository at this point in the history
  • Loading branch information
xsebek committed Jul 5, 2024
1 parent 3b872f1 commit 5d7edf0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/swarm-tui/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import Control.Monad (unless, void, when)
import Control.Monad.Extra (whenJust)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.State (MonadState, execState)
import Data.Int (Int32)
import Data.List.Extra (enumerate)
import Data.List.NonEmpty (NonEmpty (..))
import Data.List.NonEmpty qualified as NE
import Data.Map qualified as M
Expand Down
2 changes: 1 addition & 1 deletion src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Control.Applicative (liftA2, pure)
import Control.Lens as Lens
import Control.Monad (unless, when)
import Data.Foldable (toList)
import Data.List.Extra (enumerate)
import Data.Maybe (isNothing)
import Data.String (fromString)
import Data.Text qualified as T
Expand All @@ -40,7 +41,6 @@ import Swarm.TUI.Model.UI
import Swarm.TUI.View.Objective qualified as GR
import Witch (into)
import Prelude hiding (Applicative (..))
import Data.List.Extra (enumerate)

-- | Update the UI. This function is used after running the
-- game for some number of ticks.
Expand Down
4 changes: 2 additions & 2 deletions src/swarm-tui/Swarm/TUI/Controller/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Control.Lens as Lens
import Control.Monad (forM_, unless, when)
import Control.Monad.IO.Class (MonadIO (liftIO), liftIO)
import Control.Monad.State (MonadState, execState)
import Data.List.Extra (enumerate)
import Data.Map qualified as M
import Data.Set qualified as S
import Data.Text (Text)
Expand All @@ -35,7 +36,6 @@ import Swarm.Language.Syntax hiding (Key)
import Swarm.TUI.Model
import Swarm.TUI.Model.UI
import Swarm.TUI.View.Util (generateModal)
import Swarm.Util (listEnums)
import System.Clock (Clock (..), getTime)

-- | Pattern synonyms to simplify brick event handler
Expand Down Expand Up @@ -178,7 +178,7 @@ allHandlers ::
(e1 -> e2) ->
(e1 -> (Text, EventM Name AppState ())) ->
[KeyEventHandler e2 (EventM Name AppState)]
allHandlers eEmbed f = map handleEvent1 listEnums
allHandlers eEmbed f = map handleEvent1 enumerate
where
handleEvent1 e1 = let (n, a) = f e1 in onEvent (eEmbed e1) n a

Expand Down
4 changes: 2 additions & 2 deletions src/swarm-tui/Swarm/TUI/Model/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module Swarm.TUI.Model.Event (
import Brick.Keybindings
import Control.Arrow ((&&&))
import Data.Bifunctor (first)
import Data.List.Extra (enumerate)
import Data.Text (Text)
import Graphics.Vty qualified as V
import Swarm.Util (listEnums)

data SwarmEvent
= Main MainEvent
Expand Down Expand Up @@ -219,7 +219,7 @@ defaultRobotPanelBindings = allBindings $ \case
-- Helper methods

allKeyEvents :: (Ord e, Bounded e, Enum e) => (e -> Text) -> KeyEvents e
allKeyEvents f = keyEvents $ map (f &&& id) listEnums
allKeyEvents f = keyEvents $ map (f &&& id) enumerate

allBindings :: (Bounded e, Enum e) => (e -> [Binding]) -> [(e, [Binding])]
allBindings f = map (\e -> (e, f e)) [minBound .. maxBound]

0 comments on commit 5d7edf0

Please sign in to comment.