Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Patience.Map
Description
This module provides a lossless way to do
diffing between two Map
s, and ways to
manipulate the diffs.
Synopsis
- data Delta a
- 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)
- 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)
- 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
Functor Delta Source # | |
Foldable Delta Source # | |
Defined in Patience.Map Methods fold :: Monoid m => Delta m -> m foldMap :: Monoid m => (a -> m) -> Delta a -> m foldMap' :: Monoid m => (a -> m) -> Delta a -> m foldr :: (a -> b -> b) -> b -> Delta a -> b foldr' :: (a -> b -> b) -> b -> Delta a -> b foldl :: (b -> a -> b) -> b -> Delta a -> b foldl' :: (b -> a -> b) -> b -> Delta a -> b foldr1 :: (a -> a -> a) -> Delta a -> a foldl1 :: (a -> a -> a) -> Delta a -> a elem :: Eq a => a -> Delta a -> Bool maximum :: Ord a => Delta a -> a | |
Traversable Delta Source # | |
Eq a => Eq (Delta a) Source # | |
Ord a => Ord (Delta a) Source # | |
Show a => Show (Delta a) Source # | |
Generic (Delta a) Source # | |
Generic1 Delta Source # | |
type Rep (Delta a) Source # | |
Defined in Patience.Map type Rep (Delta a) = D1 ('MetaData "Delta" "Patience.Map" "patience-0.3-I62H27wz80L2IOqnO6Lhfl" 'False) ((C1 ('MetaCons "Delta" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: C1 ('MetaCons "Same" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a))) :+: (C1 ('MetaCons "Old" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: C1 ('MetaCons "New" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))) | |
type Rep1 Delta Source # | |
Defined in Patience.Map type Rep1 Delta = D1 ('MetaData "Delta" "Patience.Map" "patience-0.3-I62H27wz80L2IOqnO6Lhfl" 'False) ((C1 ('MetaCons "Delta" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1) :+: C1 ('MetaCons "Same" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1)) :+: (C1 ('MetaCons "Old" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1) :+: C1 ('MetaCons "New" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))) |
Diffing
Arguments
:: (Eq a, Ord k) | |
=> Map k a | first, old |
-> Map k a | second, new |
-> Map k (Delta a) |
|
Case analysis on Delta
getOriginals :: Delta a -> (Maybe a, Maybe a) Source #
Get the original values out of the 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.
toOriginals :: Map k (Delta a) -> (Map k a, Map k a) Source #
Reconstruct both original Map
s.
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.