Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

This module provides a lossless way to do
diffing between two `Map`

s, and ways to
manipulate the diffs.

## Synopsis

- data Delta a
- data M
- diff :: (Eq a, Ord k) => Map k a -> Map k a -> Map k (Delta a)
- getSame :: Eq a => Delta a -> Maybe a
- getOld :: Delta a -> Maybe a
- getNew :: Delta a -> Maybe a
- getDelta :: Delta a -> Maybe (a, a)
- getOriginal :: M -> Delta a -> Maybe a
- getOriginals :: Delta a -> (Maybe a, Maybe a)
- isSame :: Eq a => Delta a -> Bool
- isOld :: Delta a -> Bool
- isNew :: Delta a -> Bool
- isDelta :: Delta a -> Bool
- toSame :: Eq a => Map k (Delta a) -> Map k a
- toOld :: Map k (Delta a) -> Map k a
- toNew :: Map k (Delta a) -> Map k a
- toDelta :: Map k (Delta a) -> Map k (a, a)
- toOriginal :: M -> Map k (Delta a) -> Map k a
- toOriginals :: Map k (Delta a) -> (Map k a, Map k a)
- mapSame :: Eq a => (a -> b) -> Map k (Delta a) -> Map k b
- mapOld :: (a -> b) -> Map k (Delta a) -> Map k b
- mapNew :: (a -> b) -> Map k (Delta a) -> Map k b
- mapSame' :: Eq a => (a -> a) -> Map k (Delta a) -> Map k (Delta a)
- mapOld' :: (a -> a) -> Map k (Delta a) -> Map k (Delta a)
- mapNew' :: (a -> a) -> Map k (Delta a) -> Map k (Delta a)

# Types

The result of a diff of an entry within two `Map`

s.

In two `Map`

s m1 and m2, when performing a diff, this type encodes the following situations:

Same key, different values: Stores the two values in the Delta constructor.

Same key, same values: Stores the value in the Same constructor.

Key exists in m1 but not m2: Stores the value in the Old constructor.

Key exists in m2 but not m1: Stores the value in the New constructor.

This behaviour ensures that we don't lose any information, meaning
we can reconstruct either of the original `Map`

`k`

`a`

from a `Map`

`k`

(`Delta`

`a`

).
(Note that this slightly differs from `diff`

, which does not
care about the possibility of reconstruction).

## Instances

# Diffing

# Case analysis on

`Delta`

# Construction of special maps from a diff

toDelta :: Map k (Delta a) -> Map k (a, a) Source #

Retrieve only the `DeltaUnit`

values out of the diff map.

# Mapping

mapSame' :: Eq a => (a -> a) -> Map k (Delta a) -> Map k (Delta a) Source #

Map over all the `Same`

values, preserving the
remaining values in the map.