Safe Haskell | None |
---|

Grab bag of utility functions.

- tieredForest :: Ord k => (a -> [k]) -> [a] -> Forest (k, [a])
- tieredPostings :: [(a, Posting)] -> Forest (SubAccount, [(a, Posting)])
- filterForest :: (a -> Bool) -> Forest a -> Forest a
- balances :: ShowZeroBalances -> [(a, Posting)] -> Forest (SubAccount, Balance)
- flatten :: Forest (SubAccount, Balance) -> [(Account, Balance)]
- treeWithParents :: Tree a -> Tree (a, [a])
- forestWithParents :: Forest a -> Forest (a, [a])
- sumForest :: s -> (s -> s -> s) -> Forest (a, s) -> (Forest (a, s), s)
- sumTree :: s -> (s -> s -> s) -> Tree (a, s) -> Tree (a, s)
- boxesBalance :: [(a, Posting)] -> Balance
- labelLevels :: Tree a -> Tree (Int, a)
- sortForest :: (a -> a -> Ordering) -> Forest a -> Forest a
- sortTree :: (a -> a -> Ordering) -> Tree a -> Tree a
- lastMode :: Ord a => [a] -> Maybe a

# Documentation

:: Ord k | |

=> (a -> [k]) | Extracts a key from the elements we are putting in the tree. If this function returns an empty list for any element, the element will not appear in the tiered forest. |

-> [a] | |

-> Forest (k, [a]) |

Constructs a forest sorted into tiers based on lists of keys that are extracted from the elements.

tieredPostings :: [(a, Posting)] -> Forest (SubAccount, [(a, Posting)])Source

Takes a list of postings and puts them into a Forest. Each level of each of the trees corresponds to a sub account. The label of the node tells you the sub account name and gives you a list of the postings at that level.

filterForest :: (a -> Bool) -> Forest a -> Forest aSource

Keeps only Trees that match a given condition. First examines child trees to determine whether they should be retained. If a child tree is retained, does not delete the parent tree.

balances :: ShowZeroBalances -> [(a, Posting)] -> Forest (SubAccount, Balance)Source

Puts all Boxes into a Tree and sums the balances. Removes accounts that have empty balances if requested. Does NOT sum balances from the bottom up.

flatten :: Forest (SubAccount, Balance) -> [(Account, Balance)]Source

Takes a tree of Balances (like what is produced by the `balances`

function) and produces a flat list of accounts with the balance of
each account.

treeWithParents :: Tree a -> Tree (a, [a])Source

Takes a Tree and returns a Tree where each node has information about its parent Nodes. The list of parent nodes has the most immediate parent first and the most distant parent last.

forestWithParents :: Forest a -> Forest (a, [a])Source

Takes a Forest and returns a Forest where each node has information about its parent Nodes.

Sums a forest from the bottom up. Returns a pair, where the first element is the forest, but with the second element of each node replaced with the sum of that node and all its children. The second element is the sum of all the second elements in the forest.

Sums a tree from the bottom up.

boxesBalance :: [(a, Posting)] -> BalanceSource

labelLevels :: Tree a -> Tree (Int, a)Source

Label each level of a Tree with an integer indicating how deep it is. The top node of the tree is level 0.

sortForest :: (a -> a -> Ordering) -> Forest a -> Forest aSource

Sorts each level of a Forest.