fix: bal: better fix for treeLeaves, fixing func tests (#1782)
This commit is contained in:
parent
2bb309b073
commit
900e2167fc
@ -59,7 +59,7 @@ import Hledger.Utils.Regex
|
|||||||
import Hledger.Utils.String
|
import Hledger.Utils.String
|
||||||
import Hledger.Utils.Text
|
import Hledger.Utils.Text
|
||||||
import Hledger.Utils.Test
|
import Hledger.Utils.Test
|
||||||
import Data.Tree (foldTree, Tree)
|
import Data.Tree (foldTree, Tree (Node, subForest))
|
||||||
|
|
||||||
|
|
||||||
-- tuples
|
-- tuples
|
||||||
@ -120,9 +120,11 @@ splitAtElement x l =
|
|||||||
|
|
||||||
-- trees
|
-- trees
|
||||||
|
|
||||||
-- | Get the leaves of this tree as a list. The root node is not counted as a leaf.
|
-- | Get the leaves of this tree as a list.
|
||||||
treeLeaves :: Tree a -> [a]
|
-- The topmost node ("root" in hledger account trees) is not counted as a leaf.
|
||||||
treeLeaves = drop 1 . foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs)
|
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
|
-- text
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user