Skip to content

Commit da70559

Browse files
committed
Parser.LL.Helpers: migrate to Types.step
1 parent 176961c commit da70559

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎src/Parser/LL/Helpers.hs‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ extractNextPipe plane = maybeToEither plane $ do
103103
-- Ensure that the previous cell is empty, i.e. the current cell
104104
-- look like the first cell of a pipe
105105
prev <- case cell of
106-
'^' -> Just $ nextPos pos T.Down
107-
'v' -> Just $ nextPos pos T.Up
108-
'<' -> Just $ nextPos pos T.Right
109-
'>' -> Just $ nextPos pos T.Left
106+
'^' -> Just $ T.step T.Down pos
107+
'v' -> Just $ T.step T.Up pos
108+
'<' -> Just $ T.step T.Right pos
109+
'>' -> Just $ T.step T.Left pos
110110
_ -> Nothing
111111
prevCell <- plane P.!? prev
112112
guard (prevCell == ' ')
113113

114114
let checkNeighbours conditions =
115115
sequence_ $ (flip map) conditions $ \(dir, forbiddenChars) -> do
116-
let next = nextPos pos dir
116+
let next = T.step dir pos
117117
case plane P.!? next of
118118
Nothing -> Just ()
119119
Just cellValue ->
@@ -144,10 +144,10 @@ extractNextPipe plane = maybeToEither plane $ do
144144
if cell == ' '
145145
then acc
146146
else case (cellToDirection cell) of
147-
Nothing -> follow fdir (pos:acc) (nextPos pos dir) dir
147+
Nothing -> follow fdir (pos:acc) (T.step dir pos) dir
148148
Just nextDir ->
149149
let nextDir' = maybeReverse fdir nextDir
150-
in follow fdir (pos:acc) (nextPos pos nextDir') nextDir'
150+
in follow fdir (pos:acc) (T.step nextDir' pos) nextDir'
151151

152152
cellToDirection :: Char -> Maybe T.Direction
153153
cellToDirection '^' = Just T.Up
@@ -163,14 +163,6 @@ extractNextPipe plane = maybeToEither plane $ do
163163
maybeReverse Reverse T.Left = T.Right
164164
maybeReverse Reverse T.Right = T.Left
165165

166-
nextPos :: T.Point -> T.Direction -> T.Point
167-
nextPos pos dir =
168-
case dir of
169-
T.Left -> pos { T.x = T.x pos - 1 }
170-
T.Right -> pos { T.x = T.x pos + 1 }
171-
T.Up -> pos { T.y = T.y pos - 1 }
172-
T.Down -> pos { T.y = T.y pos + 1 }
173-
174166
headMiddleTail :: [a] -> Maybe (a, [a], a)
175167
headMiddleTail [] = Nothing
176168
headMiddleTail [_] = Nothing

0 commit comments

Comments
 (0)