From 9e9f8e11bb2728db084038c1a34272931435c30f Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 27 Jun 2017 07:02:26 +0300 Subject: Work with empty structures --- lib/Malodivo/Budget.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib') diff --git a/lib/Malodivo/Budget.hs b/lib/Malodivo/Budget.hs index 3a68fdf..c063b2a 100644 --- a/lib/Malodivo/Budget.hs +++ b/lib/Malodivo/Budget.hs @@ -167,6 +167,12 @@ that some districts can pay their shares and others can't: >>> manyToOne low medium == low True + +It works without any districts specified: + +>>> manyToOne HM.empty medium +fromList [] + -} manyToOne :: D.DistrictFunds -- ^ Amounts of available funds per district. @@ -178,6 +184,30 @@ manyToOne df b = HM.fromList $ zip ds (normalizeDown (B.amount b) fs) {-| Districts funding multiple bills. No constraints. + +>>> :set -XOverloadedStrings +>>> import qualified Data.HashMap.Strict as HM +>>> import qualified Malodivo.Types.Bill as B +>>> import qualified Malodivo.Types.District as D +>>> import qualified Malodivo.Types.Ministry as M + +>>> let scienceA = B.Bill { B.amount = 10, B.name = "Science A", B.ministry = M.Science } +>>> let welfareA = B.Bill { B.amount = 100, B.name = "Welfare A", B.ministry = M.Welfare } + + +It works without any districts specified: + +>>> snd . head $ manyToMany HM.empty [scienceA] +fromList [] + + +It works without bills: + +>>> manyToMany HM.empty [] +[] +>>> let funds = HM.fromList [(D.Palolene, 100), (D.Lakos, 200)] +>>> manyToMany funds [] +[] -} manyToMany :: D.DistrictFunds -- ^ Amounts of available funds per district. -- cgit v1.2.3