Skip to content

Commit

Permalink
Update exercises/practice/bowling/.meta/Example.roc
Browse files Browse the repository at this point in the history
Improve isOver with list pattern matching

Co-authored-by: Isaac Van Doren <69181572+isaacvando@users.noreply.github.com>
  • Loading branch information
ageron and isaacvando authored Sep 29, 2024
1 parent 28881a2 commit 8582db8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions exercises/practice/bowling/.meta/Example.roc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ checkMax10Pins = \lastFrame, pins ->

isOver : Game -> Bool
isOver = \@Game { frames } ->
if List.len frames < 10 then
Bool.false
else
when frames |> List.last is
Ok (Ball1 _) | Ok (Spare _ _) | Ok Strike | Ok (StrikeFill1 _) -> Bool.false
Ok (Ball2 _ _) | Ok (SpareFill _) | Ok (StrikeFill2 _ _) -> Bool.true
Err ListWasEmpty -> crash "Impossible, we ensured that length is at least 10"
when frames is
_ if List.len frames < 10 -> Bool.false
[.., Ball1 _] | [.., Spare _ _] | [.., Strike] | [.., StrikeFill1 _] -> Bool.false
[.., Ball2 _ _] | [.., SpareFill _] | [.., StrikeFill2 _ _] -> Bool.true
_ -> Bool.false

roll : Game, U64 -> Result Game [MoreThan10Pins, GameOver]
roll = \@Game { frames }, pins ->
Expand Down

0 comments on commit 8582db8

Please sign in to comment.