lib: +postingNegate

This commit is contained in:
Simon Michael 2025-01-29 09:42:15 -10:00
parent 0dca0911f3
commit bbb06209e7

View File

@ -63,6 +63,7 @@ module Hledger.Data.Posting (
-- * arithmetic
sumPostings,
postingNegate,
postingNegateMainAmount,
-- * rendering
showPosting,
@ -381,6 +382,13 @@ accountNamesFromPostings = S.toList . S.fromList . map paccount
sumPostings :: [Posting] -> MixedAmount
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
-- | Negate the posting's main amount and balance assertion amount if any.
postingNegate :: Posting -> Posting
postingNegate p@Posting{pamount=a, pbalanceassertion=mb} =
p{pamount=negate a, pbalanceassertion=fmap balanceAssertionNegate mb}
where
balanceAssertionNegate b@BalanceAssertion{baamount=ba} = b{baamount=negate ba}
-- | Negate the posting's main amount but not the balance assertion amount.
postingNegateMainAmount :: Posting -> Posting
postingNegateMainAmount p@Posting{pamount=a} = p{pamount=negate a}