3 ms·
I gotta say that, after not having used it in about 4 years, I love looking at Haskell again. One question: could CurrentTile.hs be DRYed up? https://github.c
by CoffeeDregs 12y ago
I gotta say that, after not having used it in about 4 years, I love looking at Haskell again.
One question: could CurrentTile.hs be DRYed up? https://github.com/egonSchiele/chips/blob/master/src/Chips/CurrentTile.hs https://github.com/egonSchiele/chips/blob/master/src/Chips/C...
This repeating pattern seems ripe for DRYing:
checkCurTile (Chip _) = do
liftIO $ playSound (soundDir ++ "collect_chip.wav") False
tileAt Current .= (Empty def)
checkCurTile (Gate _) = do
liftIO $ playSound (soundDir ++ "door.wav") False
tileAt Current .= (Empty def)
checkCurTile (KeyYellow _) = do
yellowKeyCount += 1
tileAt Current .= (Empty def)
checkCurTile (KeyBlue _) = do
blueKeyCount += 1
tileAt Current .= (Empty def)
[...]
- egonschiele 12y agoAh yeah, it could definitely be refactored. There's some repetitive code in there.
- codygman 12y agoSorry for bad formatting and not compile checking the code, but this is an improvement imo: checkCurTile b = do case b of Chip -> liftIO $ playSound (soundDir ++ "collect_chip.wav") False Gate -> liftIO $ playSound (soundDir ++ "door.wav") False (KeyYellow _) -> yellowKeyCount += 1 (KeyBlue _) -> blueKeyCount += 1 tileAt Current .= (Empty def)