Skip to content

Instantly share code, notes, and snippets.

@joshcough
Last active April 1, 2016 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshcough/4f9f8cf08ab2be1e3599c3989c5d2c09 to your computer and use it in GitHub Desktop.
Save joshcough/4f9f8cf08ab2be1e3599c3989c5d2c09 to your computer and use it in GitHub Desktop.
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
@joshcough
Copy link
Author

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 add bifunctors to the cabal file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment