Clean up, use std lib functions

This commit is contained in:
Sam Tay 2018-12-26 20:22:50 -05:00
parent 5b8d419b24
commit 09de01695c
2 changed files with 3 additions and 9 deletions

View file

@ -35,6 +35,7 @@ import qualified Linear.V2 as LV
import System.Random (getStdRandom, randomR) import System.Random (getStdRandom, randomR)
import Prelude hiding (Left, Right) import Prelude hiding (Left, Right)
import Control.Monad (mfilter)
import Data.Bool (bool) import Data.Bool (bool)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Monoid (First(..)) import Data.Monoid (First(..))
@ -225,7 +226,7 @@ rotate g = g & block .~ nextB
nextB = fromMaybe blk $ getFirst . mconcat $ First <$> bs nextB = fromMaybe blk $ getFirst . mconcat $ First <$> bs
bs = map ($ blk) safeFuncs bs = map ($ blk) safeFuncs
safeFuncs = map (mkSafe .) funcs safeFuncs = map (mkSafe .) funcs
mkSafe = boolMaybe (isValidBlockPosition brd) mkSafe = mfilter (isValidBlockPosition brd) . pure
funcs = [rotate', rotate' . translate Left, rotate' . translate Right] funcs = [rotate', rotate' . translate Left, rotate' . translate Right]
blk = g ^. block blk = g ^. block
brd = g ^. board brd = g ^. board
@ -308,9 +309,5 @@ shuffle xs
(y :< ys) = Seq.viewl right (y :< ys) = Seq.viewl right
fmap (y <|) (shuffle $ left >< ys) fmap (y <|) (shuffle $ left >< ys)
-- | Take predicate and input and transform to Maybe
boolMaybe :: (a -> Bool) -> a -> Maybe a
boolMaybe p a = if p a then Just a else Nothing
v2 :: (a, a) -> V2 a v2 :: (a, a) -> V2 a
v2 (x, y) = V2 x y v2 (x, y) = V2 x y

View file

@ -1,8 +1,6 @@
name: tetris name: tetris
version: 0.1.2.0 version: 0.1.2.0
-- synopsis: homepage: https://github.com/samtay/tetris#readme
-- description:
homepage: https://github.com/SamTay/tetris#readme
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Sam Tay author: Sam Tay
@ -26,7 +24,6 @@ library
, linear , linear
, random , random
, vty , vty
default-language: Haskell2010 default-language: Haskell2010
executable tetris executable tetris