hledger-lib-1.52.1: A library providing the core functionality of hledger

Safe Haskell | None
Language | GHC2021

Hledger.Data.PeriodData

Contents

- Orphan instances

Description

Data values for zero or more report periods, and for the pre-report period. Report periods are assumed to be contiguous, and represented only by start dates (as keys of an IntMap).

Synopsis

- periodDataFromList :: a -> [(Day, a)] -> PeriodData a
- periodDataToList :: PeriodData a -> (a, [(Day, a)])
- lookupPeriodData :: Day -> PeriodData a -> Maybe (Day, a)
- lookupPeriodDataOrHistorical :: Day -> PeriodData a -> (Maybe Day, a)
- insertPeriodData :: Semigroup a => Maybe Day -> a -> PeriodData a -> PeriodData a
- opPeriodData :: (a -> b -> c) -> PeriodData a -> PeriodData b -> PeriodData c
- mergePeriodData :: (a -> c) -> (b -> c) -> (a -> b -> c) -> PeriodData a -> PeriodData b -> PeriodData c
- padPeriodData :: a -> PeriodData b -> PeriodData a -> PeriodData a
- tests_PeriodData :: TestTree

# Documentation

periodDataFromList :: a -> [(Day, a)] -> PeriodData a Source #

Construct a `PeriodData` from a historical data value and a list of (period start, period data) pairs.

periodDataToList :: PeriodData a -> (a, [(Day, a)]) Source #

Convert `PeriodData` to a historical data value and a list of (period start, period data) pairs.

lookupPeriodData :: Day -> PeriodData a -> Maybe (Day, a) Source #

Get the data for the period containing the given `Day`, and that period's start date. If the day is after the end of the last period, it is assumed to be within the last period. If the day is before the start of the first period (ie, in the historical period), return Nothing.

lookupPeriodDataOrHistorical :: Day -> PeriodData a -> (Maybe Day, a) Source #

Get the data for the period containing the given `Day`, and that period's start date. If the day is after the end of the last period, it is assumed to be within the last period. If the day is before the start of the first period (ie, in the historical period), return the data for the historical period and no start date.

insertPeriodData :: Semigroup a => Maybe Day -> a -> PeriodData a -> PeriodData a Source #

Set historical or period data in the appropriate location in a `PeriodData`.

opPeriodData :: (a -> b -> c) -> PeriodData a -> PeriodData b -> PeriodData c Source #

Merge two `PeriodData`, using the given operation to combine their data values.

This will drop keys if they are not present in both `PeriodData`.

mergePeriodData :: (a -> c) -> (b -> c) -> (a -> b -> c) -> PeriodData a -> PeriodData b -> PeriodData c Source #

Merge two `PeriodData`, using the given operations for combining data that's only in the first, only in the second, or in both, respectively.

padPeriodData :: a -> PeriodData b -> PeriodData a -> PeriodData a Source #

Pad out the date map of a `PeriodData` so that every key from another `PeriodData` is present.

tests_PeriodData :: TestTree Source #

# Orphan instances

Foldable1 PeriodData Source # |

Instance details

Methods

fold1 :: Semigroup m => PeriodData m -> m Source #

foldMap1 :: Semigroup m => (a -> m) -> PeriodData a -> m Source #

foldMap1' :: Semigroup m => (a -> m) -> PeriodData a -> m Source #

toNonEmpty :: PeriodData a -> NonEmpty a Source #

maximum :: Ord a => PeriodData a -> a Source #

minimum :: Ord a => PeriodData a -> a Source #

head :: PeriodData a -> a Source #

last :: PeriodData a -> a Source #

foldrMap1 :: (a -> b) -> (a -> b -> b) -> PeriodData a -> b Source #

foldlMap1' :: (a -> b) -> (b -> a -> b) -> PeriodData a -> b Source #

foldlMap1 :: (a -> b) -> (b -> a -> b) -> PeriodData a -> b Source #

foldrMap1' :: (a -> b) -> (a -> b -> b) -> PeriodData a -> b Source #

Foldable PeriodData Source # |

Instance details

Methods

fold :: Monoid m => PeriodData m -> m Source #

foldMap :: Monoid m => (a -> m) -> PeriodData a -> m Source #

foldMap' :: Monoid m => (a -> m) -> PeriodData a -> m Source #

foldr :: (a -> b -> b) -> b -> PeriodData a -> b Source #

foldr' :: (a -> b -> b) -> b -> PeriodData a -> b Source #

foldl :: (b -> a -> b) -> b -> PeriodData a -> b Source #

foldl' :: (b -> a -> b) -> b -> PeriodData a -> b Source #

foldr1 :: (a -> a -> a) -> PeriodData a -> a Source #

foldl1 :: (a -> a -> a) -> PeriodData a -> a Source #

toList :: PeriodData a -> [a] Source #

null :: PeriodData a -> Bool Source #

length :: PeriodData a -> Int Source #

elem :: Eq a => a -> PeriodData a -> Bool Source #

maximum :: Ord a => PeriodData a -> a Source #

minimum :: Ord a => PeriodData a -> a Source #

sum :: Num a => PeriodData a -> a Source #

product :: Num a => PeriodData a -> a Source #

Traversable PeriodData Source # |
Instance details Methods traverse :: Applicative f => (a -> f b) -> PeriodData a -> f (PeriodData b) Source # sequenceA :: Applicative f => PeriodData (f a) -> f (PeriodData a) Source # mapM :: Monad m => (a -> m b) -> PeriodData a -> m (PeriodData b) Source # sequence :: Monad m => PeriodData (m a) -> m (PeriodData a) Source #
Monoid a => Monoid (PeriodData a) Source # |
Instance details Methods mempty :: PeriodData a Source # mappend :: PeriodData a -> PeriodData a -> PeriodData a Source # mconcat :: [PeriodData a] -> PeriodData a Source #
Semigroup a => Semigroup (PeriodData a) Source # | The Semigroup instance for `PeriodData` simply takes the union of keys in the date map section. This may not be the result you want if the keys are not identical.
Instance details Methods (<>) :: PeriodData a -> PeriodData a -> PeriodData a Source # sconcat :: NonEmpty (PeriodData a) -> PeriodData a Source # stimes :: Integral b => b -> PeriodData a -> PeriodData a Source #
Show a => Show (PeriodData a) Source # |
Instance details Methods showsPrec :: Int -> PeriodData a -> ShowS Source # show :: PeriodData a -> String Source # showList :: [PeriodData a] -> ShowS Source #