diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-06-27 05:37:41 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-06-27 05:37:41 +0300 |
commit | 78004194a4d9dfabd5e64d72751f3270d3034217 (patch) | |
tree | 7b5067a58f94d6a6fe3712d5e21ab1ffffe0ef96 /cmd/Main | |
parent | 20dbc9b0166f02b80b42f6ed0cff73396b2e48e6 (diff) | |
download | molodivo-78004194a4d9dfabd5e64d72751f3270d3034217.tar.gz |
Remove I/O format knowledge from library functions
Diffstat (limited to 'cmd/Main')
-rw-r--r-- | cmd/Main/Output.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/Main/Output.hs b/cmd/Main/Output.hs new file mode 100644 index 0000000..107e8fd --- /dev/null +++ b/cmd/Main/Output.hs @@ -0,0 +1,29 @@ +{- +This modules describes output data for the command line utlity. +-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} + +module Main.Output + ( Output + , encode + ) where + +import GHC.Generics (Generic) + +import Data.Aeson (ToJSON) + +import Malodivo.Types.Bill (Bill) +import Malodivo.Types.District (DistrictFunds, DistrictInfo, df2di) + +type Output = [BillBudget] + +-- | JSON-friendly type. It describes contribution of each district into a bill. +data BillBudget = BillBudget + { bill :: Bill + , districts :: [DistrictInfo] + } deriving (Generic, ToJSON) + +-- | Translate into JSON-friendly format. +encode :: [(Bill, DistrictFunds)] -> Output +encode = map (\(b, df) -> BillBudget {bill = b, districts = df2di df}) |