From a759a6e02e54be455c4bf90a59d28ce9e8e73639 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 1 Oct 2022 18:35:49 -1000 Subject: [PATCH] dev: lib: note changed cost handling in amount arithmetic --- hledger-lib/Hledger/Data/Amount.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 94b603127..028f63b9b 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -585,10 +585,12 @@ mixedAmount :: Amount -> MixedAmount mixedAmount a = Mixed $ M.singleton (amountKey a) a -- | Add an Amount to a MixedAmount, normalising the result. +-- Amounts with different costs are kept separate. maAddAmount :: MixedAmount -> Amount -> MixedAmount maAddAmount (Mixed ma) a = Mixed $ M.insertWith sumSimilarAmountsUsingFirstPrice (amountKey a) a ma -- | Add a collection of Amounts to a MixedAmount, normalising the result. +-- Amounts with different costs are kept separate. maAddAmounts :: Foldable t => MixedAmount -> t Amount -> MixedAmount maAddAmounts = foldl' maAddAmount @@ -596,15 +598,18 @@ maAddAmounts = foldl' maAddAmount maNegate :: MixedAmount -> MixedAmount maNegate = transformMixedAmount negate --- | Sum two MixedAmount. +-- | Sum two MixedAmount, keeping the cost of the first if any. +-- Amounts with different costs are kept separate (since 2021). maPlus :: MixedAmount -> MixedAmount -> MixedAmount maPlus (Mixed as) (Mixed bs) = Mixed $ M.unionWith sumSimilarAmountsUsingFirstPrice as bs -- | Subtract a MixedAmount from another. +-- Amounts with different costs are kept separate. maMinus :: MixedAmount -> MixedAmount -> MixedAmount maMinus a = maPlus a . maNegate -- | Sum a collection of MixedAmounts. +-- Amounts with different costs are kept separate. maSum :: Foldable t => t MixedAmount -> MixedAmount maSum = foldl' maPlus nullmixedamt