| Copyright | Jeremy Groven |
|---|---|
| License | BSD3 |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.StableTree.Persist
Description
Logic for dealing with the actual persistence of Stable Trees. The key
exports here are Error, load, and store. A user needs to make an
appropriate Error type to report storage errors, and then the load and
store functions can just do their thing. If necessary, a user can also
implement Serialize for custom data types.
- class Error e where
- stableTreeError :: Text -> e
- data Fragment k v
- = FragmentBranch { }
- | FragmentBottom {
- fragmentObjectID :: ObjectID
- fragmentMap :: Map k v
- store :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (a -> ObjectID -> Fragment k v -> m (Either e a)) -> a -> StableTree k v -> m (Either e a)
- store' :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (ObjectID -> Fragment k v -> m (Maybe e)) -> StableTree k v -> m (Either e ObjectID)
- load :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (a -> ObjectID -> m (Either e (a, Fragment k v))) -> a -> ObjectID -> m (Either e (a, StableTree k v))
- load' :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (ObjectID -> m (Either e (Fragment k v))) -> ObjectID -> m (Either e (StableTree k v))
Documentation
Things go wrong with end-user storage, but things can also go wrong with
reconstructing tree values. Implement stableTreeError to allow load and
store to report their own errors.
Methods
stableTreeError :: Text -> e Source
A Fragment is a user-visible part of a tree, i.e. a single node in the
tree that can actually be manipulated by a user. This is useful when doing
the work of persisting trees. See toFragments
and fromFragments for functions to convert
between Fragments and Trees. see store and
load for functions related to storing and
retrieving Fragments.
Constructors
| FragmentBranch | |
Fields
| |
| FragmentBottom | |
Fields
| |
store :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (a -> ObjectID -> Fragment k v -> m (Either e a)) -> a -> StableTree k v -> m (Either e a) Source
Record the tree into storage. This works like a fold, where the function takes an accumulating state and each tree fragment to store, while returning either an error message (which will abort the loop immediately) or the next state for the accumulator.
Any fragment referring to other fragments (FragmentBranch fragments) will
be given to the fold only after all their children have been given to the
fold. Exact ordering beyond that is not guaranteed, but the current
behaviour is post-order depth-first traversal.
store' :: (Monad m, Error e, Ord k, Serialize k, StableKey k, Serialize v) => (ObjectID -> Fragment k v -> m (Maybe e)) -> StableTree k v -> m (Either e ObjectID) Source
Alternate store function that acts more like a map than a fold. See store
for details.