Skip to content

Commit

Permalink
Patterns <3
Browse files Browse the repository at this point in the history
  • Loading branch information
The1Penguin committed Sep 24, 2024
1 parent a5157cf commit b1bfa7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion mat-chalmers.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ library
, word8 == 0.1.3
, extra >= 1.7.16 && <= 1.8
, vector-space >= 0.16 && <0.18
, time >= 1.11 && <1.20

executable mat-chalmers
main-is: Main.hs
Expand Down
20 changes: 14 additions & 6 deletions src/Model/Linsen.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts, OverloadedStrings, LambdaCase #-}
{-# LANGUAGE FlexibleContexts, OverloadedStrings, LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}

module Model.Linsen
(
Expand All @@ -25,8 +26,8 @@ import Data.List.Extra ( (!?) )
import Data.Text.Lazy ( Text
, replace
, strip )
import Data.Thyme ( parseTime )
import Data.Time.Format (TimeLocale (..) )
import Data.Thyme ( parseTime
, TimeLocale (..) )
import Data.Thyme.Calendar ( Day )
import Data.Thyme.Calendar.WeekDate ( weekDate
, _wdDay )
Expand Down Expand Up @@ -70,6 +71,13 @@ swedishTimeLocale = TimeLocale
, knownTimeZones = []
}

pattern MeatDish :: Integer
pattern MeatDish = 3
pattern FishDish :: Integer
pattern FishDish = 8
pattern VegDish :: Integer
pattern VegDish = 13

fetch
:: (MonadHttp m, MonadIO m, MonadThrow m)
=> m Value -- ^ A JSON response or horrible crash
Expand Down Expand Up @@ -128,9 +136,9 @@ parse day =

menuParser :: [Value] -> Parser [Menu]
menuParser = pure . (zip [0 :: Integer ..] >=> \case
(3 ,vs) -> [vs] -- Index of Meat dish
(8 ,vs) -> [vs] -- Index of Fish dish
(13,vs) -> [vs] -- Index of Veg dish
(MeatDish ,vs) -> [vs]
(FishDish ,vs) -> [vs]
(VegDish ,vs) -> [vs]
_ -> [])
<=< ap (zipWithM sumFood) tail

Expand Down

0 comments on commit b1bfa7e

Please sign in to comment.