Skip to content

Commit 0bdcf97

Browse files
committed
Use NonEmpty from semigroups
1 parent 0334a6d commit 0bdcf97

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

7startups.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ library
4040
random == 1.*,
4141
split == 0.2.*,
4242
ansi-wl-pprint == 0.6.*,
43-
operational == 0.2.*
43+
operational == 0.2.*,
44+
semigroups == 0.13.*
4445
-- hs-source-dirs:
4546
default-language: Haskell2010
4647

Startups/GameTypes.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import qualified Data.Map.Strict as M
2020
import Control.Monad.Operational
2121
import Control.Monad.State.Strict
2222
import Control.Monad.Error
23+
import Data.List.NonEmpty
2324
import Control.Applicative
2425
import System.Random
2526

@@ -64,16 +65,8 @@ data PlayerAction = PlayerAction ActionType Card
6465
data ActionType = Play | Drop | BuildCompany
6566
deriving Eq
6667

67-
-- | Some types for non empty lists
68-
data NonEmpty a = NonEmpty a [a]
69-
7068
_NonEmpty :: Prism' [a] (NonEmpty a)
71-
_NonEmpty = prism fromNonEmpty toNonEmpty
72-
where
73-
fromNonEmpty (NonEmpty x xs) = x : xs
74-
toNonEmpty l = case l of
75-
[] -> Left l
76-
(x:xs) -> Right (NonEmpty x xs)
69+
_NonEmpty = prism' toList nonEmpty
7770

7871
-- | This describe the capabilities needed to write the rules, when no
7972
-- interaction with the player is required.

Startups/Interpreter.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Startups.GameTypes
88
import qualified Data.Map.Strict as M
99
import Control.Monad.Operational
1010
import Control.Monad.State.Strict
11+
import Data.List.NonEmpty
1112

1213
data OperationDict m = OperationDict { _doPlayerDecision :: Age -> Turn -> PlayerId -> NonEmpty Card -> GameState -> m (PlayerAction, Exchange)
1314
, _doAskCard :: Age -> PlayerId -> NonEmpty Card -> GameState -> Message -> m Card

0 commit comments

Comments
 (0)