penny-lib-0.16.0.0: Extensible double-entry accounting system - library

Safe HaskellNone

Penny.Cabin.Balance.Util

Description

Grab bag of utility functions.

Synopsis

Documentation

tieredForestSource

Arguments

:: 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.

sumForestSource

Arguments

:: s

Zero

-> (s -> s -> s)

Combiner

-> Forest (a, s) 
-> (Forest (a, s), s) 

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.

sumTreeSource

Arguments

:: s

Zero

-> (s -> s -> s)

Combiner

-> Tree (a, s) 
-> Tree (a, s) 

Sums a tree from the bottom up.

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.

sortTree :: (a -> a -> Ordering) -> Tree a -> Tree aSource

Sorts each level of a Tree.

lastMode :: Ord a => [a] -> Maybe aSource

Like lastModeBy but using Ord.