lib: Replace {pr,prr}Negate with fmap negate.

This commit is contained in:
Stephen Morgan 2020-07-08 18:53:55 +10:00 committed by Simon Michael
parent f518da747c
commit 463eee7bf4
2 changed files with 6 additions and 20 deletions

View File

@ -166,7 +166,7 @@ compoundBalanceReportWith ropts q j priceoracle subreportspecs = cbr
(r:rs) -> sconcat $ fmap subreportTotal (r:|rs)
where
subreportTotal (_, sr, increasestotal) =
(if increasestotal then id else prrNegate) $ prTotals sr
(if increasestotal then id else fmap negate) $ prTotals sr
cbr = CompoundPeriodicReport "" colspans subreports overalltotals
@ -523,11 +523,10 @@ calculateTotalsRow ropts rows =
-- | Map the report rows to percentages and negate if needed
postprocessReport :: ReportOpts -> MultiBalanceReport -> MultiBalanceReport
postprocessReport ropts =
maybeInvert . maybePercent
postprocessReport ropts = maybePercent . maybeInvert
where
maybeInvert = if invert_ ropts then prNegate else id
maybePercent = if percent_ ropts then prPercent else id
maybeInvert = if invert_ ropts then fmap negate else id
maybePercent = if percent_ ropts then prPercent else id
prPercent (PeriodicReport spans rows totalrow) =
PeriodicReport spans (map percentRow rows) (percentRow totalrow)

View File

@ -17,13 +17,10 @@ module Hledger.Reports.ReportTypes
, Average
, periodicReportSpan
, prNegate
, prNormaliseSign
, prMapName
, prMapMaybeName
, prrNegate
, CompoundPeriodicReport(..)
, CBCSubreportSpec(..)
@ -115,18 +112,8 @@ periodicReportSpan (PeriodicReport colspans _ _) = DateSpan (spanStart $ head co
-- | Given a PeriodicReport and its normal balance sign,
-- if it is known to be normally negative, convert it to normally positive.
prNormaliseSign :: Num b => NormalSign -> PeriodicReport a b -> PeriodicReport a b
prNormaliseSign NormallyNegative = prNegate
prNormaliseSign _ = id
-- | Flip the sign of all amounts in a PeriodicReport.
prNegate :: Num b => PeriodicReport a b -> PeriodicReport a b
prNegate (PeriodicReport colspans rows totalsrow) =
PeriodicReport colspans (map prrNegate rows) (prrNegate totalsrow)
-- | Flip the sign of all amounts in a PeriodicReportRow.
prrNegate :: Num b => PeriodicReportRow a b -> PeriodicReportRow a b
prrNegate (PeriodicReportRow name amts tot avg) =
PeriodicReportRow name (map negate amts) (-tot) (-avg)
prNormaliseSign NormallyNegative = fmap negate
prNormaliseSign NormallyPositive = id
-- | Map a function over the row names.
prMapName :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c