From 900e2167fcfd26f897526b67d730b43546733bec Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 8 Dec 2021 18:14:08 -1000 Subject: [PATCH] fix: bal: better fix for treeLeaves, fixing func tests (#1782) --- hledger-lib/Hledger/Utils.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Utils.hs b/hledger-lib/Hledger/Utils.hs index c45ab6972..95c93b720 100644 --- a/hledger-lib/Hledger/Utils.hs +++ b/hledger-lib/Hledger/Utils.hs @@ -59,7 +59,7 @@ import Hledger.Utils.Regex import Hledger.Utils.String import Hledger.Utils.Text import Hledger.Utils.Test -import Data.Tree (foldTree, Tree) +import Data.Tree (foldTree, Tree (Node, subForest)) -- tuples @@ -120,9 +120,11 @@ splitAtElement x l = -- trees --- | Get the leaves of this tree as a list. The root node is not counted as a leaf. -treeLeaves :: Tree a -> [a] -treeLeaves = drop 1 . foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs) +-- | Get the leaves of this tree as a list. +-- The topmost node ("root" in hledger account trees) is not counted as a leaf. +treeLeaves :: Show a => Tree a -> [a] +treeLeaves Node{subForest=[]} = [] +treeLeaves t = foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs) t -- text