perdure-0.2.1: Robust persistence for acyclic immutable data

Safe HaskellNone

Database.Perdure.History

Synopsis

Documentation

data History a Source

The History type is used as the state type so as to keep some snapshots of the past, in case data is lost due to a programming error by the application developer. It is an homogenous collection so the argument type has to take care of versionning. To avoid needless reserialization of the past states, the argument type should be a Ref type.

We keep the last n samples inserted, then n samples keeping one out of every two, then n samples keeping one out of every four... Currently n is hard coded to 2.

current :: History a -> aSource

The history is never empty, so it is safe to get the current sample.

insert :: a -> History a -> History aSource

Add a newer state to the history

updateHistory :: Monad m => StateT a m b -> StateT (History a) m bSource

Changes a transformation on a into a transformation on 'History a'. Adds a new state into the History.

updateHistoryM :: Monad m => StateT a m b -> StateT (History a) m bSource

Changes a transformation on a into a transformation on 'History a'. Adds a new state into the History, unless the state has not changed. Uses State.