diff options
-rw-r--r-- | cmd/Main.hs | 7 | ||||
-rw-r--r-- | lib/Malodivo/Budget.hs | 30 |
2 files changed, 32 insertions, 5 deletions
diff --git a/cmd/Main.hs b/cmd/Main.hs index 7af6a83..dbe6dac 100644 --- a/cmd/Main.hs +++ b/cmd/Main.hs @@ -4,7 +4,6 @@ module Main ( main ) where -import Control.Monad (when) import Data.Maybe (fromMaybe) import Data.Version (showVersion) import System.Environment (getArgs) @@ -12,7 +11,6 @@ import System.Exit (die) import Data.Aeson (eitherDecode, encode) import qualified Data.ByteString.Lazy as L -import qualified Data.HashMap.Strict as HM import System.Console.Docopt.NoTH (isPresent, longOption, parseArgsOrExit, parseUsageOrExit, usage) import Text.InterpolatedString.Perl6 (qc) @@ -52,9 +50,8 @@ process = do let allBills = I.bills si suppliedFunds = di2df $ I.districts si ministryLimits = mi2ml $ fromMaybe [] (I.ministries si) - in do when (HM.null suppliedFunds) $ die "We needs at least one district" - L.putStr . encode . O.encode $ - manyToManyLimited suppliedFunds ministryLimits allBills + in L.putStr . encode . O.encode $ + manyToManyLimited suppliedFunds ministryLimits allBills main :: IO () main = do 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. |