penny-0.32.0.2: Extensible double-entry accounting system

Safe HaskellNone

Penny.Cabin.Balance.Util

Description

Grab bag of utility functions.

Synopsis

Documentation

tieredForestSource

Arguments

:: Ord b 
=> (a -> [b])

Function that, when applied to an item, returns a list. The items will be placed into a tiered forest according to each list.

-> [a]

List of items to put into the forest

-> ([a], Forest ([a], b))

fst is the list of items for which the function returned an empty list. The forest includes all other items.

Places items into a tiered forest.

tieredPostings :: [(a, Posting)] -> ([(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)] -> (Balance, 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 :: (Balance, 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. Also adds in the first balance, which is for Accounts that have no sub-accounts.

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.

sumForest :: Monoid s => Forest (a, s) -> (Forest (a, s), s)Source

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.

sumTree :: Monoid s => Tree (a, s) -> Tree (a, s)Source

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.