patience-0.2.1.0: Patience diff and longest increasing subsequence

Patience.Map

Description

This module provides a lossless way to do diffing between two Maps, and ways to manipulate the diffs.

Synopsis

# Types

data Delta a Source #

The result of a diff of an entry within two Maps.

In two Maps 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).

Constructors

 Delta !a !a Same !a Old !a New !a
Instances
 Source # Instance detailsDefined in Patience.Map Methodsfmap :: (a -> b) -> Delta a -> Delta b #(<\$) :: a -> Delta b -> Delta a # Source # Instance detailsDefined in Patience.Map Methodsfold :: Monoid m => Delta m -> 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 #toList :: Delta a -> [a] #null :: Delta a -> Bool #length :: Delta a -> Int #elem :: Eq a => a -> Delta a -> Bool #maximum :: Ord a => Delta a -> a #minimum :: Ord a => Delta a -> a #sum :: Num a => Delta a -> a #product :: Num a => Delta a -> a # Source # Instance detailsDefined in Patience.Map Methodstraverse :: Applicative f => (a -> f b) -> Delta a -> f (Delta b) #sequenceA :: Applicative f => Delta (f a) -> f (Delta a) #mapM :: Monad m => (a -> m b) -> Delta a -> m (Delta b) #sequence :: Monad m => Delta (m a) -> m (Delta a) # Eq a => Eq (Delta a) Source # Instance detailsDefined in Patience.Map Methods(==) :: Delta a -> Delta a -> Bool #(/=) :: Delta a -> Delta a -> Bool # Ord a => Ord (Delta a) Source # Instance detailsDefined in Patience.Map Methodscompare :: Delta a -> Delta a -> Ordering #(<) :: Delta a -> Delta a -> Bool #(<=) :: Delta a -> Delta a -> Bool #(>) :: Delta a -> Delta a -> Bool #(>=) :: Delta a -> Delta a -> Bool #max :: Delta a -> Delta a -> Delta a #min :: Delta a -> Delta a -> Delta a # Show a => Show (Delta a) Source # Instance detailsDefined in Patience.Map MethodsshowsPrec :: Int -> Delta a -> ShowS #show :: Delta a -> String #showList :: [Delta a] -> ShowS # Generic (Delta a) Source # Instance detailsDefined in Patience.Map Associated Typestype Rep (Delta a) :: Type -> Type # Methodsfrom :: Delta a -> Rep (Delta a) x #to :: Rep (Delta a) x -> Delta a # Source # Instance detailsDefined in Patience.Map Associated Typestype Rep1 Delta :: k -> Type # Methodsfrom1 :: Delta a -> Rep1 Delta a #to1 :: Rep1 Delta a -> Delta a # type Rep (Delta a) Source # Instance detailsDefined in Patience.Map type Rep (Delta a) = D1 (MetaData "Delta" "Patience.Map" "patience-0.2.1.0-EAz1vDfw89ELF6u9pc2Ygq" 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 # Instance detailsDefined in Patience.Map type Rep1 Delta = D1 (MetaData "Delta" "Patience.Map" "patience-0.2.1.0-EAz1vDfw89ELF6u9pc2Ygq" 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)))

data M Source #

M1 = First Map, M2 = Second Map. Used as an argument for functions that care about which Map to reconstruct.

Constructors

 M1 M2

# Diffing

Arguments

 :: (Eq a, Ord k) => Map k a first, old Map -> Map k a second, new Map -> Map k (Delta a) Map encoding the diff

Takes two Maps and returns a Map from the same key type to Delta a, where Delta a encodes differences between entries.

# Case analysis on Delta

getSame :: Eq a => Delta a -> Maybe a Source #

Potentially get the Same value out of a Delta.

getOld :: Delta a -> Maybe a Source #

Potentially get the Old value out of a Delta.

getNew :: Delta a -> Maybe a Source #

Potentially get the New value out of a Delta.

getDelta :: Delta a -> Maybe (a, a) Source #

Potentially get the Changed value out of a Delta.

getOriginal :: M -> Delta a -> Maybe a Source #

Potentially get the original value out of the Delta.

getOriginals :: Delta a -> (Maybe a, Maybe a) Source #

Get the original values out of the Delta.

isSame :: Eq a => Delta a -> Bool Source #

Is the Delta an encoding of same values?

isOld :: Delta a -> Bool Source #

Is the Delta an encoding of old values?

isNew :: Delta a -> Bool Source #

Is the Delta an encoding of new values?

isDelta :: Delta a -> Bool Source #

Is the Delta an encoding of changed values?

# Construction of special maps from a diff

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

Retrieve the Same values out of the diff map.

toOld :: Map k (Delta a) -> Map k a Source #

Retrieve only the Old values out of the diff map.

toNew :: Map k (Delta a) -> Map k a Source #

Retrieve only the New values out of the diff map.

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

Retrieve only the DeltaUnit values out of the diff map.

toOriginal :: M -> Map k (Delta a) -> Map k a Source #

Construct either the old Map or new Map from a diff

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

Reconstruct both original Maps.

# Mapping

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

Map over all Same values, returning a map of just the transformed values. This can be more efficient than calling toSame and then Data.Map's map.

mapOld :: (a -> b) -> Map k (Delta a) -> Map k b Source #

Map over all Old values, returning a map of just the transformed values. This can be more efficient than calling toOld and then Data.Map's map.

mapNew :: (a -> b) -> Map k (Delta a) -> Map k b Source #

Map over all New values, returning a map of just the transformed values. This can be more efficient than calling toNew and then Data.Map's map.

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.

mapOld' :: (a -> a) -> Map k (Delta a) -> Map k (Delta a) Source #

Map over all the Old values, preserving the remaining values in the map.

mapNew' :: (a -> a) -> Map k (Delta a) -> Map k (Delta a) Source #

Map over all the New values, preserving the remaining values in the map.