Skip to content

Instantly share code, notes, and snippets.

@StevenXL
Created January 20, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenXL/913d0532b56c634b794e4aac2e095e67 to your computer and use it in GitHub Desktop.
Save StevenXL/913d0532b56c634b794e4aac2e095e67 to your computer and use it in GitHub Desktop.
Sum
calculateReport :: Budget -> [Transaction] -> Report
calculateReport budget transactions =
Report
{ budgetProfit = budgetProfit'
, netProfit = netProfit'
, difference = netProfit' - budgetProfit'
}
where
budgetProfit' = budgetIncome budget - budgetExpenditure budget
netProfit' = getSum (foldMap asProfit transactions)
asProfit (Sale m) = pure m
asProfit (Purchase m) = pure (negate m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment