Skip to content

Commit

Permalink
Now shouldn't produce errors
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed Jun 3, 2024
1 parent b6fa09e commit 92d28ab
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Model/Linsen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ parse
parse day =
failWithNoMenu
(parseEither
( withObject "Parse meals"
$ (.: "docs")
>=> ((!? (6 - (day ^. weekDate . _wdDay))) <&> \case
Nothing -> fail "Day doesnt exist" -- TODO: Should early return to shortcircuit to []
Just v -> pure v)
>=> (.: "richText")
>=> (.: "root")
>=> (.: "children")
>=> pure . (\v -> if length v >= 9 then v else mempty)
>=> menuParser
(let index = 6 - day ^. weekDate . _wdDay in
if index `notElem` [1..5] then
pure . const []
else
withObject "Parse meals"
$ (.: "docs")
>=> (\case
Nothing -> fail "Failed to index into days"
Just v -> pure v) . (!? index)
>=> (.: "richText")
>=> (.: "root")
>=> (.: "children")
>=> menuParser . (\v' -> if length v' >= 9 then v' else mempty)
)
)
>=> menusToEitherNoLunch
Expand Down

0 comments on commit 92d28ab

Please sign in to comment.