diff --git a/BalanceCommand.hs b/BalanceCommand.hs index d9d1a5767..4a6cd35e2 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -131,19 +131,13 @@ showLedgerAccountBalances l maxdepth = then "" else printf "--------------------\n%20s\n" $ showAmountRounded total where - acctbranches = branches $ pruneBoringBranches $ ledgerAccountTree maxdepth l + acctbranches = branches $ pruneZeroBalanceBranches $ ledgerAccountTree maxdepth l filteredacctbranches = branches $ ledgerFilteredAccountTree maxdepth (acctpat l) l total = sum $ map (abalance . root) filteredacctbranches --- | Remove boring branches and leaves from a tree of accounts. --- A boring branch contains only accounts which have a 0 balance. -pruneBoringBranches :: Tree Account -> Tree Account -pruneBoringBranches = --- treefilter hastxns . - treefilter hasbalance - where - hasbalance = not . isZeroAmount . abalance - hastxns = (> 0) . length . atransactions +-- | Remove all-zero-balance branches and leaves from a tree of accounts. +pruneZeroBalanceBranches :: Tree Account -> Tree Account +pruneZeroBalanceBranches = treefilter (not . isZeroAmount . abalance) -- | Get the string representation of a tree of accounts. -- The ledger from which the accounts come is required so that diff --git a/Tests.hs b/Tests.hs index f1cdcee54..244918800 100644 --- a/Tests.hs +++ b/Tests.hs @@ -93,10 +93,10 @@ tests = assertparseequal (Amount (getcurrency "$") 47.18 2) (parsewith ledgeramount " $47.18") assertparseequal (Amount (getcurrency "$") 1 0) (parsewith ledgeramount " $1.") - ,"pruneBoringBranches" ~: do + ,"pruneZeroBalanceBranches" ~: do atree <- liftM (ledgerAccountTree 99) $ ledgerfromfile "sample.ledger" assertequal 13 (length $ flatten $ atree) - assertequal 12 (length $ flatten $ pruneBoringBranches $ atree) + assertequal 12 (length $ flatten $ pruneZeroBalanceBranches $ atree) ] balancecommandtests =