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

Safe HaskellSafe-Inferred

Penny.Lincoln.Family

Contents

Description

A Transaction consists of a TopLine (information common to all postings, such as the DateTime) and of at least two Postings. This data relationship is so important and useful that it is expressed in these modules. This module has its own functions and re-exports functions and types from other modules in this hierarchy. There are handy accessor functions for the records within each of the family types, but these are not exported due to name conflicts; if you want these simply import the necessary module (maybe qualified).

Synopsis

Family types

data Family p c Source

A Family has one parent (ah, the anomie, sorry) and at least two children.

Constructors

Family p c c [c] 

Instances

(Eq p, Eq c) => Eq (Family p c) 
(Show p, Show c) => Show (Family p c) 

data Child p c Source

A Child has at least one sibling and a parent.

Constructors

Child c c [c] p 

Instances

(Show p, Show c) => Show (Child p c) 

data Siblings a Source

Describes the siblings of a family, but tells you nothing about the parent. There are always at least two Siblings.

Constructors

Siblings a a [a] 

Mapping families

mapChildrenA :: Applicative m => (a -> m b) -> Family p a -> m (Family p b)Source

Maps over all children, in order starting with child 1, then child 2, then the children in the list from left to right.

mapChildren :: (a -> b) -> Family p a -> Family p bSource

Maps over all children.

mapParentA :: Applicative m => (a -> m b) -> Family a c -> m (Family b c)Source

Maps over the parent in an Applicative.

mapParent :: (a -> b) -> Family a c -> Family b cSource

Maps over the parent.

Functions to manipulate families

children :: Family p c -> Siblings (Child p c)Source

Gets a family's children. The Child type contains information on the parent, and each Child contains information on the other Siblings.

orphans :: Family p c -> Siblings cSource

Separates the children from their parent.

adopt :: p -> Siblings c -> Family p cSource

Unites a parent and some siblings into one family; the dual of orphans.

marryWith :: (p1 -> p2 -> p3) -> (c1 -> c2 -> c3) -> Family p1 c1 -> Family p2 c2 -> Family p3 c3Source

Marries two families into one. This function is rather cruel: if one family has more children than the other family, then the extra children are discarded. That is, all children must pair one-by-one.

marry :: Family p1 c1 -> Family p2 c2 -> Family (p1, p2) (c1, c2)Source

marryWith a tupling function.

divorceWith :: (p1 -> (p2, p3)) -> (c1 -> (c2, c3)) -> Family p1 c1 -> (Family p2 c2, Family p3 c3)Source

Splits up a family.

divorce :: Family (p1, p2) (c1, c2) -> (Family p1 c1, Family p2 c2)Source

divorceWith an untupling function.

filterChildren :: (a -> Bool) -> Family p a -> Maybe (Family p a)Source

Filters the children. Fails if there are not at least two children after filtering. Retains the original order of the children (after removing the children you don't want.)

find :: (p -> c -> Bool) -> Family p c -> Maybe cSource

Finds the first child matching a predicate.

collapse :: Siblings (NonEmpty a) -> Siblings aSource

Change a Siblings of NonEmpty lists to a Siblings. The original order of the elements contained in the Siblings and within the NonEmpty lists is preserved.