Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace minBound to maxBound with enumerate #2017

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/swarm-scenario/Swarm/Game/World/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Swarm.Game.World.Parse where
import Control.Monad (void)
import Control.Monad.Combinators.Expr (Operator (..), makeExprParser)
import Control.Monad.Combinators.NonEmpty qualified as CNE (sepBy1)
import Data.List.Extra (enumerate)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Void (Void)
Expand Down Expand Up @@ -189,7 +190,7 @@ parseCellItem =
<*> parseName

parseCellTag :: Parser CellTag
parseCellTag = choice (map mkCellTagParser [minBound .. maxBound :: CellTag])
parseCellTag = choice (map mkCellTagParser (enumerate @CellTag))
where
mkCellTagParser ct = ct <$ string' (T.drop 4 $ showT ct)

Expand Down
3 changes: 2 additions & 1 deletion src/swarm-scenario/Swarm/Game/World/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Data.Foldable qualified as F
import Data.Functor.Const qualified as F
import Data.Kind (Type)
import Data.List (foldl')
import Data.List.Extra (enumerate)
import Data.List.NonEmpty qualified as NE
import Data.Map (Map)
import Data.Map qualified as M
Expand Down Expand Up @@ -636,7 +637,7 @@ resolveCellItem (mCellTag, item) = case mCellTag of
Nothing -> do
-- The item was not tagged; try resolving in all possible ways and choose
-- the first that works
maybeCells <- mapM (`resolverByTag` item) [minBound .. maxBound :: CellTag]
maybeCells <- mapM (`resolverByTag` item) (enumerate @CellTag)
case F.asum maybeCells of
Nothing -> throwError $ NotAnything item
Just cell -> return cell
Expand Down