8000 refactor(day2): make parseInput truly point-free · IndecisionTree/adventofcode2022@7fe09ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fe09ce

Browse files
refactor(day2): make parseInput truly point-free
1 parent 2278f70 commit 7fe09ce

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

solutions/Days/Day02.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
module Days.Day02 (day02) where
22

33
import AOC (Solution (..))
4-
import Data.Bifunctor (second)
4+
import Control.Arrow ((>>>), (***), second)
55
import Data.Maybe (fromMaybe)
66
import qualified Data.Text as T
77

88
day02 :: Solution
99
day02 = Solution parseInput part1 part2
10+
1011
data RPS = Rock | Paper | Scissors
1112
deriving (Show, Eq, Enum, Bounded)
1213

1314
data Action = Lose | Draw | Win
1415
deriving (Show, Eq)
1516

1617
parseInput :: T.Text -> [(RPS, T.Text)]
17-
parseInput = fmap pLine . T.lines
18+
parseInput = fmap (T.breakOn " " >>> translate table *** T.tail) . T.lines
1819
where
19-
pLine l = let [a, b] = T.words l in (translate table a, b)
2020
table = [("A", Rock), ("B", Paper), ("C", Scissors)]
2121

2222
part1 :: [(RPS, T.Text)] -> Int

0 commit comments

Comments
 (0)
0