From fd729beabfd5cf0c69e0a03b46e816e43f6608ad Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Fri, 10 Jul 2020 12:07:40 +1000 Subject: [PATCH] lib: Work around hiding deprecation warnings, don't traverse zeros twice in normaliseHelper. --- hledger-lib/Hledger/Data/Amount.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 90fa3c451..d2b705c34 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -40,10 +40,6 @@ exchange rates. -} --- Silence safe 0.3.18's deprecation warnings for (max|min)imum(By)?Def for now --- (may hide other deprecation warnings too). https://github.com/ndmitchell/safe/issues/26 -{-# OPTIONS_GHC -Wno-warnings-deprecations #-} - {-# LANGUAGE StandaloneDeriving, RecordWildCards, OverloadedStrings #-} module Hledger.Data.Amount ( @@ -140,7 +136,7 @@ import qualified Data.Map as M import Data.Map (findWithDefault) import Data.Maybe import qualified Data.Text as T -import Safe (maximumDef) +import Safe (lastDef, maximumMay) import Text.Printf import Hledger.Data.Types @@ -507,9 +503,7 @@ normaliseHelper squashprices (Mixed as) | null nonzeros = Mixed [newzero] | otherwise = Mixed nonzeros where - newzero = case filter (/= "") (map acommodity zeros) of - _:_ -> last zeros - _ -> nullamt + newzero = lastDef nullamt $ filter (not . T.null . acommodity) zeros (zeros, nonzeros) = partition amountIsZero $ map sumSimilarAmountsUsingFirstPrice $ groupBy groupfn $ @@ -698,7 +692,7 @@ showMixedAmountWithoutPrice c m = intercalate "\n" $ map showamt as (if c && isNegativeAmount a then color Dull Red else id) $ printf (printf "%%%ds" width) $ showAmountWithoutPrice c a where - width = maximumDef 0 $ map (length . showAmount) as + width = fromMaybe 0 . maximumMay $ map (length . showAmount) as mixedAmountStripPrices :: MixedAmount -> MixedAmount mixedAmountStripPrices (Mixed as) = Mixed $ map (\a -> a{aprice=Nothing}) as