|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | +module Compose where |
| 3 | + |
| 4 | +import qualified Control.Applicative as Applicative |
| 5 | +import qualified Data.Function as Function |
| 6 | +import qualified Data.Time.Calendar as Calendar |
| 7 | +import qualified Data.Time.Clock as Clock |
| 8 | +import qualified Data.Maybe as Maybe |
| 9 | + |
| 10 | +import Transaction |
| 11 | +import Currency |
| 12 | +import CurryingPartialApplication |
| 13 | + |
| 14 | +-- OPPGAVE 4.1: Lag en funksjon som konverterer fra DKK til NOK. |
| 15 | +dkkToNok :: Double -> Double |
| 16 | +dkkToNok = dkkToSek . sekToUsd . usdToGbp . eurToNok . gbpToEur |
| 17 | + |
| 18 | +bySalary :: Transaction -> Bool |
| 19 | +bySalary a = transactionType a == "salary" |
| 20 | + |
| 21 | +-- Oppgave 4.3: Calculate total earned salary |
| 22 | +sumSalary :: [Transaction] -> Double |
| 23 | +sumSalary = sum . map amount . filter bySalary |
| 24 | + |
| 25 | +-- Oppgave 4.4: Calculate amount spent on a product in a specific currency |
| 26 | +amountSpentOnProductByCurrency :: Currency -> Product -> [Transaction] -> Double |
| 27 | +amountSpentOnProductByCurrency c p = sum . map amount . filter filterFn |
| 28 | + where |
| 29 | + filterFn :: Transaction -> Bool |
| 30 | + filterFn t = transactionProduct t == p && currency t == c |
| 31 | + |
| 32 | +amountSpentOnProductInNok :: Product -> [Transaction] -> Double |
| 33 | +amountSpentOnProductInNok = amountSpentOnProductByCurrency "NOK" |
| 34 | + |
| 35 | +pantsBoughtInNok :: [Transaction] -> Double |
| 36 | +pantsBoughtInNok = amountSpentOnProductInNok "Pants" |
| 37 | + |
| 38 | +shoesBoughtInNok :: [Transaction] -> Double |
| 39 | +shoesBoughtInNok = amountSpentOnProductInNok "Shoes" |
0 commit comments