This library has been created as a fork of the library https://github.com/liamoc/patches-vector by Liam O’Connor. His work made the creation of this library for maps a lot simpler. Thanks!
A patch is a collection of modifications (edits) to be made to a map from keys to values. Commonly found in version control systems, patches are also a simple example of a groupoid, supporting (partial) composition and inversion.
This library provides a pleasant interface for working with patches to maps with any type of element. It includes patch composition, inversion, and application, as well as a way to compute a patch between two maps.
It also includes a simple implementation of the operational transformation (OT) function to resolve diverging patches from the same document. This allows for reasonably painless implementation of merge functions, as well as many applications in distributed editing of documents. This operation also has an interpretation in terms of groupoids, where the transform function is the pushout of two diverging patches.
This library is extensively covered by a comprehensive suite of
QuickCheck properties, which are written into the documentation and
run with doctest
.
The actual package only depends on base
, microlens
, and containers
.
It is released under the BSD3 license.
patches-map
is released on Hackage and is available in the usual way:
$ cabal update $ cabal install patches-map
You can also use stack
if you prefer:
$ stack install patches-map
A variety of stack-*.yaml
files are provided in this repository for various LTS snapshots.
The full Haddock documentation is available on Hackage. Mostly, construct patches using fromList
or diff
, compose them with the Monoid
instance, invert them with inverse
,
and apply them to a map with apply
.
The transform
function can be used to resolve diverging patches, and transformWith
lets you select a merging strategy, such as ours
or theirs
, rather than the default
mappend
. See the Haddock documentation for more information.