Last active
April 1, 2016 06:38
-
-
Save joshcough/4f9f8cf08ab2be1e3599c3989c5d2c09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Scrabble/Board/Board.hs b/src/Scrabble/Board/Board.hs | |
index 7741e22..a847ed1 100644 | |
--- a/src/Scrabble/Board/Board.hs | |
+++ b/src/Scrabble/Board/Board.hs | |
@@ -25,30 +25,31 @@ module Scrabble.Board.Board | |
import Data.Aeson (ToJSON, FromJSON, toJSON, parseJSON, withArray) | |
import Data.Array (Array, listArray) | |
-import qualified Data.Array as A | |
+import Data.Bifunctor (second) | |
import Data.List (intercalate) | |
-import qualified Data.Maybe as Maybe | |
import Data.Set (Set) | |
-import qualified Data.Set as Set | |
-import qualified Data.Vector as V | |
import GHC.Generics | |
import Scrabble.Bag | |
import Scrabble.Board.Orientation | |
import Scrabble.Board.Point | |
import Scrabble.Board.Square | |
+import qualified Data.Array as A | |
+import qualified Data.Maybe as Maybe | |
+import qualified Data.Set as Set | |
+import qualified Data.Vector as V | |
+ | |
data Board = Board { | |
contents :: (Array Point Square) | |
} deriving (Eq, Ord, Generic) | |
instance ToJSON Board where | |
- toJSON (Board b) = toJSON . fmap g . filter f $ A.assocs b where | |
- f (_,s) = Maybe.isJust $ tile s | |
- g (p,s) = (p,tile s) | |
+ toJSON (Board b) = | |
+ toJSON . fmap (second tile) $ filter (taken . snd) (A.assocs b) | |
instance FromJSON Board where | |
parseJSON = withArray "Board" $ \arr -> | |
- Board . (newBoard //) <$> mapM parseJSON (V.toList arr) | |
+ putTiles newBoard <$> mapM parseJSON (V.toList arr) | |
type Row = Array Int Square | |
type Col = Array Int Square |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A bunch of this is just import reorganization, but line 10 was added:
import Data.Bifunctor (second)
. The main important diffs start at line 32. I also had to addbifunctors
to the cabal file.