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) | ||||
|       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) | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user