reduce repetition

main
Daniel Barlow 2023-01-22 17:50:48 +00:00
parent c02c0aabca
commit 1ba4399221
1 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,5 @@
(local { : view } (require :fennel)) (local { : view } (require :fennel))
(local { : merge } (require :lume))
(macro expect [text actual expected] (macro expect [text actual expected]
`(let [actual# ,actual] `(let [actual# ,actual]
@ -14,10 +15,10 @@
(fn command [rover [cmd & cmds]] (fn command [rover [cmd & cmds]]
(let [r1 (let [r1
(match rover.direction (match rover.direction
:n {:x rover.x :y (+ rover.y 1) :direction :n : command} :n (merge rover {:y (+ rover.y 1)})
:s {:x rover.x :y (- rover.y 1) :direction :s : command} :s (merge rover {:y (- rover.y 1)})
:w {:x (- rover.x 1) :y rover.y :direction :w : command} :w (merge rover {:x (- rover.x 1)})
:e {:x (+ rover.x 1) :y rover.y :direction :e : command})] :e (merge rover {:x (+ rover.x 1)}))]
(if (next cmds) (if (next cmds)
(r1:command cmds) (r1:command cmds)
r1))) r1)))