From 64e3e5c54dd68ba51140b57aee38e2e2a437f8b6 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Fri, 11 Sep 2020 11:59:16 +1000 Subject: [PATCH] lib: Improve documentation for StringFormat, remove type alias for Valuation. --- hledger-lib/Hledger/Data/StringFormat.hs | 10 ++++++---- hledger-lib/Hledger/Reports/MultiBalanceReport.hs | 9 +++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hledger-lib/Hledger/Data/StringFormat.hs b/hledger-lib/Hledger/Data/StringFormat.hs index 834a094ce..b0f58dbeb 100644 --- a/hledger-lib/Hledger/Data/StringFormat.hs +++ b/hledger-lib/Hledger/Data/StringFormat.hs @@ -31,10 +31,12 @@ import Hledger.Utils.Test -- | A format specification/template to use when rendering a report line item as text. -- --- A format is a sequence of components; each is either a literal --- string, or a hledger report item field with specified width and --- justification whose value will be interpolated at render time. --- This includes an optional width for any overlines. +-- A format is an optional width, along with a sequence of components; +-- each is either a literal string, or a hledger report item field with +-- specified width and justification whose value will be interpolated +-- at render time. The optional width determines the length of the +-- overline to draw above the totals row; if it is Nothing, then the +-- maximum width of all lines is used. -- -- A component's value may be a multi-line string (or a -- multi-commodity amount), in which case the final string will be diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs index e43b69561..052f7d08c 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs @@ -82,9 +82,6 @@ type CompoundBalanceReport = CompoundPeriodicReport DisplayName MixedAmount -- type alias just to remind us which AccountNames might be depth-clipped, below. type ClippedAccountName = AccountName --- Type alias for a valuation function -type Valuation = Day -> MixedAmount -> MixedAmount - -- | Generate a multicolumn balance report for the matched accounts, -- showing the change of balance, accumulated balance, or historical balance @@ -241,7 +238,7 @@ makeReportQuery ropts reportspan dateqcons = if date2_ ropts then Date2 else Date -- | Make a valuation function for valuating MixedAmounts and a given Day -makeValuation :: ReportOpts -> Journal -> PriceOracle -> Valuation +makeValuation :: ReportOpts -> Journal -> PriceOracle -> Day -> MixedAmount -> MixedAmount makeValuation ropts j priceoracle day = case value_ ropts of Nothing -> id Just v -> mixedAmountApplyValuation priceoracle styles day mreportlast (today_ ropts) multiperiod v @@ -331,7 +328,7 @@ acctChangesFromPostings ropts ps = HM.fromList [(aname a, a) | a <- as] -- | Accumulate and value amounts, as specified by the report options. -- -- Makes sure all report columns have an entry. -accumValueAmounts :: ReportOpts -> Valuation -> [DateSpan] +accumValueAmounts :: ReportOpts -> (Day -> MixedAmount -> MixedAmount) -> [DateSpan] -> HashMap ClippedAccountName Account -> HashMap ClippedAccountName (Map DateSpan Account) -> HashMap ClippedAccountName (Map DateSpan Account) @@ -369,7 +366,7 @@ accumValueAmounts ropts valuation colspans startbals acctchanges = -- PARTIAL: -- | Lay out a set of postings grouped by date span into a regular matrix with rows -- given by AccountName and columns by DateSpan, then generate a MultiBalanceReport -- from the columns. -generateMultiBalanceReport :: ReportOpts -> Journal -> Valuation -> [DateSpan] +generateMultiBalanceReport :: ReportOpts -> Journal -> (Day -> MixedAmount -> MixedAmount) -> [DateSpan] -> Map DateSpan [Posting] -> HashMap AccountName Account -> MultiBalanceReport generateMultiBalanceReport ropts j valuation colspans colps startbals = report