lib: Replace {pr,prr}Negate with fmap negate.
This commit is contained in:
parent
f518da747c
commit
463eee7bf4
@ -166,7 +166,7 @@ compoundBalanceReportWith ropts q j priceoracle subreportspecs = cbr
|
|||||||
(r:rs) -> sconcat $ fmap subreportTotal (r:|rs)
|
(r:rs) -> sconcat $ fmap subreportTotal (r:|rs)
|
||||||
where
|
where
|
||||||
subreportTotal (_, sr, increasestotal) =
|
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
|
cbr = CompoundPeriodicReport "" colspans subreports overalltotals
|
||||||
|
|
||||||
@ -523,10 +523,9 @@ calculateTotalsRow ropts rows =
|
|||||||
|
|
||||||
-- | Map the report rows to percentages and negate if needed
|
-- | Map the report rows to percentages and negate if needed
|
||||||
postprocessReport :: ReportOpts -> MultiBalanceReport -> MultiBalanceReport
|
postprocessReport :: ReportOpts -> MultiBalanceReport -> MultiBalanceReport
|
||||||
postprocessReport ropts =
|
postprocessReport ropts = maybePercent . maybeInvert
|
||||||
maybeInvert . maybePercent
|
|
||||||
where
|
where
|
||||||
maybeInvert = if invert_ ropts then prNegate else id
|
maybeInvert = if invert_ ropts then fmap negate else id
|
||||||
maybePercent = if percent_ ropts then prPercent else id
|
maybePercent = if percent_ ropts then prPercent else id
|
||||||
|
|
||||||
prPercent (PeriodicReport spans rows totalrow) =
|
prPercent (PeriodicReport spans rows totalrow) =
|
||||||
|
|||||||
@ -17,13 +17,10 @@ module Hledger.Reports.ReportTypes
|
|||||||
, Average
|
, Average
|
||||||
|
|
||||||
, periodicReportSpan
|
, periodicReportSpan
|
||||||
, prNegate
|
|
||||||
, prNormaliseSign
|
, prNormaliseSign
|
||||||
, prMapName
|
, prMapName
|
||||||
, prMapMaybeName
|
, prMapMaybeName
|
||||||
|
|
||||||
, prrNegate
|
|
||||||
|
|
||||||
, CompoundPeriodicReport(..)
|
, CompoundPeriodicReport(..)
|
||||||
, CBCSubreportSpec(..)
|
, CBCSubreportSpec(..)
|
||||||
|
|
||||||
@ -115,18 +112,8 @@ periodicReportSpan (PeriodicReport colspans _ _) = DateSpan (spanStart $ head co
|
|||||||
-- | Given a PeriodicReport and its normal balance sign,
|
-- | Given a PeriodicReport and its normal balance sign,
|
||||||
-- if it is known to be normally negative, convert it to normally positive.
|
-- if it is known to be normally negative, convert it to normally positive.
|
||||||
prNormaliseSign :: Num b => NormalSign -> PeriodicReport a b -> PeriodicReport a b
|
prNormaliseSign :: Num b => NormalSign -> PeriodicReport a b -> PeriodicReport a b
|
||||||
prNormaliseSign NormallyNegative = prNegate
|
prNormaliseSign NormallyNegative = fmap negate
|
||||||
prNormaliseSign _ = id
|
prNormaliseSign NormallyPositive = 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)
|
|
||||||
|
|
||||||
-- | Map a function over the row names.
|
-- | Map a function over the row names.
|
||||||
prMapName :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c
|
prMapName :: (a -> b) -> PeriodicReport a c -> PeriodicReport b c
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user