patch-0.0.8.0: Data structures for describing changes to other data structures.

Safe HaskellNone
LanguageHaskell2010

Data.Patch.MapWithMove

Contents

Description

Patches of this type can insert, delete, and also move values from one key to another.

Synopsis

Documentation

newtype PatchMapWithMove k (v :: Type) Source #

Patch a Map with additions, deletions, and moves. Invariant: If key k1 is coming from From_Move k2, then key k2 should be going to Just k1, and vice versa. There should never be any unpaired From/To keys.

Constructors

PatchMapWithMove' 

Fields

Bundled Patterns

pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v 
Instances
FunctorWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

imap :: (k -> a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #

FoldableWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

ifoldMap :: Monoid m => (k -> a -> m) -> PatchMapWithMove k a -> m #

ifoldMap' :: Monoid m => (k -> a -> m) -> PatchMapWithMove k a -> m #

ifoldr :: (k -> a -> b -> b) -> b -> PatchMapWithMove k a -> b #

ifoldl :: (k -> b -> a -> b) -> b -> PatchMapWithMove k a -> b #

ifoldr' :: (k -> a -> b -> b) -> b -> PatchMapWithMove k a -> b #

ifoldl' :: (k -> b -> a -> b) -> b -> PatchMapWithMove k a -> b #

TraversableWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

itraverse :: Applicative f => (k -> a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b) #

FunctorWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

imap :: (k -> a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #

imapped :: IndexedSetter k (PatchMapWithMove k a) (PatchMapWithMove k b) a b #

FoldableWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

ifoldMap :: Monoid m => (k -> a -> m) -> PatchMapWithMove k a -> m #

ifolded :: IndexedFold k (PatchMapWithMove k a) a #

ifoldr :: (k -> a -> b -> b) -> b -> PatchMapWithMove k a -> b #

ifoldl :: (k -> b -> a -> b) -> b -> PatchMapWithMove k a -> b #

ifoldr' :: (k -> a -> b -> b) -> b -> PatchMapWithMove k a -> b #

ifoldl' :: (k -> b -> a -> b) -> b -> PatchMapWithMove k a -> b #

TraversableWithIndex k (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

itraverse :: Applicative f => (k -> a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b) #

itraversed :: IndexedTraversal k (PatchMapWithMove k a) (PatchMapWithMove k b) a b #

Functor (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

fmap :: (a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #

(<$) :: a -> PatchMapWithMove k b -> PatchMapWithMove k a #

Foldable (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

fold :: Monoid m => PatchMapWithMove k m -> m #

foldMap :: Monoid m => (a -> m) -> PatchMapWithMove k a -> m #

foldr :: (a -> b -> b) -> b -> PatchMapWithMove k a -> b #

foldr' :: (a -> b -> b) -> b -> PatchMapWithMove k a -> b #

foldl :: (b -> a -> b) -> b -> PatchMapWithMove k a -> b #

foldl' :: (b -> a -> b) -> b -> PatchMapWithMove k a -> b #

foldr1 :: (a -> a -> a) -> PatchMapWithMove k a -> a #

foldl1 :: (a -> a -> a) -> PatchMapWithMove k a -> a #

toList :: PatchMapWithMove k a -> [a] #

null :: PatchMapWithMove k a -> Bool #

length :: PatchMapWithMove k a -> Int #

elem :: Eq a => a -> PatchMapWithMove k a -> Bool #

maximum :: Ord a => PatchMapWithMove k a -> a #

minimum :: Ord a => PatchMapWithMove k a -> a #

sum :: Num a => PatchMapWithMove k a -> a #

product :: Num a => PatchMapWithMove k a -> a #

Traversable (PatchMapWithMove k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

traverse :: Applicative f => (a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b) #

sequenceA :: Applicative f => PatchMapWithMove k (f a) -> f (PatchMapWithMove k a) #

mapM :: Monad m => (a -> m b) -> PatchMapWithMove k a -> m (PatchMapWithMove k b) #

sequence :: Monad m => PatchMapWithMove k (m a) -> m (PatchMapWithMove k a) #

(Eq k, Eq v) => Eq (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

(Ord k, Ord v) => Ord (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

(Ord k, Read k, Read v) => Read (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

(Show k, Show v) => Show (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Ord k => Semigroup (PatchMapWithMove k v) Source #

Compose patches having the same effect as applying the patches in turn: applyAlways (p <> q) == applyAlways p . applyAlways q

Instance details

Defined in Data.Patch.MapWithMove

Ord k => Monoid (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Wrapped (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Associated Types

type Unwrapped (PatchMapWithMove k v) :: Type #

Ord k => Patch (PatchMapWithMove k v) Source #

Apply the insertions, deletions, and moves to a given Map

Instance details

Defined in Data.Patch.MapWithMove

Associated Types

type PatchTarget (PatchMapWithMove k v) :: Type Source #

PatchMapWithMove k1 v1 ~ t => Rewrapped (PatchMapWithMove k2 v2) t Source # 
Instance details

Defined in Data.Patch.MapWithMove

type Unwrapped (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

type PatchTarget (PatchMapWithMove k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v) Source #

Create a tPatchMapWithMove, validating it

patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v Source #

Create a tPatchMapWithMove that inserts everything in the given Map

insertMapKey :: k -> v -> PatchMapWithMove k v Source #

Make a tPatchMapWithMove k v which has the effect of inserting or updating a value v to the given key k, like insert.

moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v Source #

Make a tPatchMapWithMove k v which has the effect of moving the value from the first key k to the second key k, equivalent to:

    delete src (maybe map (insert dst) (Map.lookup src map))

swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v Source #

Make a tPatchMapWithMove k v which has the effect of swapping two keys in the mapping, equivalent to:

    let aMay = Map.lookup a map
        bMay = Map.lookup b map
    in maybe id (Map.insert a) (bMay <> aMay)
     . maybe id (Map.insert b) (aMay <> bMay)
     . Map.delete a . Map.delete b $ map

deleteMapKey :: k -> PatchMapWithMove k v Source #

Make a tPatchMapWithMove k v which has the effect of deleting a key in the mapping, equivalent to delete.

unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v Source #

Wrap a Map k (NodeInfo k v) representing patch changes into a tPatchMapWithMove k v, without checking any invariants.

Warning: when using this function, you must ensure that the invariants of tPatchMapWithMove are preserved; they will not be checked.

patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v] Source #

Returns all the new elements that will be added to the Map.

patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v Source #

Return a Map k v with all the inserts/updates from the given tPatchMapWithMove k v.

patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v Source #

Create a tPatchMapWithMove that, if applied to the given Map, will sort its values using the given ordering function. The set keys of the Map is not changed.

patchThatChangesAndSortsMapWith :: (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v Source #

Create a tPatchMapWithMove that, if applied to the first Map provided, will produce a Map with the same values as the second Map but with the values sorted with the given ordering function.

patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v Source #

Create a tPatchMapWithMove that, if applied to the first Map provided, will produce the second Map.

Node Info

newtype NodeInfo k (v :: Type) Source #

Holds the information about each key: where its new value should come from, and where its old value should go to

Constructors

NodeInfo' 

Fields

Bundled Patterns

pattern NodeInfo :: From k v -> To k -> NodeInfo k v 
Instances
Functor (NodeInfo k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

fmap :: (a -> b) -> NodeInfo k a -> NodeInfo k b #

(<$) :: a -> NodeInfo k b -> NodeInfo k a #

Foldable (NodeInfo k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

fold :: Monoid m => NodeInfo k m -> m #

foldMap :: Monoid m => (a -> m) -> NodeInfo k a -> m #

foldr :: (a -> b -> b) -> b -> NodeInfo k a -> b #

foldr' :: (a -> b -> b) -> b -> NodeInfo k a -> b #

foldl :: (b -> a -> b) -> b -> NodeInfo k a -> b #

foldl' :: (b -> a -> b) -> b -> NodeInfo k a -> b #

foldr1 :: (a -> a -> a) -> NodeInfo k a -> a #

foldl1 :: (a -> a -> a) -> NodeInfo k a -> a #

toList :: NodeInfo k a -> [a] #

null :: NodeInfo k a -> Bool #

length :: NodeInfo k a -> Int #

elem :: Eq a => a -> NodeInfo k a -> Bool #

maximum :: Ord a => NodeInfo k a -> a #

minimum :: Ord a => NodeInfo k a -> a #

sum :: Num a => NodeInfo k a -> a #

product :: Num a => NodeInfo k a -> a #

Traversable (NodeInfo k) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

traverse :: Applicative f => (a -> f b) -> NodeInfo k a -> f (NodeInfo k b) #

sequenceA :: Applicative f => NodeInfo k (f a) -> f (NodeInfo k a) #

mapM :: Monad m => (a -> m b) -> NodeInfo k a -> m (NodeInfo k b) #

sequence :: Monad m => NodeInfo k (m a) -> m (NodeInfo k a) #

(Eq k, Eq p) => Eq (NodeInfo k p) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

(==) :: NodeInfo k p -> NodeInfo k p -> Bool #

(/=) :: NodeInfo k p -> NodeInfo k p -> Bool #

(Ord k, Ord p) => Ord (NodeInfo k p) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

compare :: NodeInfo k p -> NodeInfo k p -> Ordering #

(<) :: NodeInfo k p -> NodeInfo k p -> Bool #

(<=) :: NodeInfo k p -> NodeInfo k p -> Bool #

(>) :: NodeInfo k p -> NodeInfo k p -> Bool #

(>=) :: NodeInfo k p -> NodeInfo k p -> Bool #

max :: NodeInfo k p -> NodeInfo k p -> NodeInfo k p #

min :: NodeInfo k p -> NodeInfo k p -> NodeInfo k p #

(Read k, Read p) => Read (NodeInfo k p) Source # 
Instance details

Defined in Data.Patch.MapWithMove

(Show k, Show p) => Show (NodeInfo k p) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Methods

showsPrec :: Int -> NodeInfo k p -> ShowS #

show :: NodeInfo k p -> String #

showList :: [NodeInfo k p] -> ShowS #

Wrapped (NodeInfo k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Associated Types

type Unwrapped (NodeInfo k v) :: Type #

Methods

_Wrapped' :: Iso' (NodeInfo k v) (Unwrapped (NodeInfo k v)) #

NodeInfo k1 v1 ~ t => Rewrapped (NodeInfo k2 v2) t Source # 
Instance details

Defined in Data.Patch.MapWithMove

type Unwrapped (NodeInfo k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

type Unwrapped (NodeInfo k v) = NodeInfo k (Proxy v)

bitraverseNodeInfo :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> NodeInfo k0 v0 -> f (NodeInfo k1 v1) Source #

nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v Source #

Change the From value of a tNodeInfo

nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v) Source #

Change the From value of a tNodeInfo, using a Functor (or Applicative, Monad, etc.) action to get the new value

nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v Source #

Set the To field of a tNodeInfo

From

newtype From k (v :: Type) Source #

Describe how a key's new value should be produced

Constructors

From' 

Fields

Bundled Patterns

pattern From_Insert :: v -> From k v

Insert the given value here

pattern From_Delete :: From k v

Delete the existing value, if any, from here

pattern From_Move :: k -> From k v

Move the value here from the given key

Instances
Wrapped (From k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

Associated Types

type Unwrapped (From k v) :: Type #

Methods

_Wrapped' :: Iso' (From k v) (Unwrapped (From k v)) #

From k1 v1 ~ t => Rewrapped (From k2 v2) t Source # 
Instance details

Defined in Data.Patch.MapWithMove

type Unwrapped (From k v) Source # 
Instance details

Defined in Data.Patch.MapWithMove

type Unwrapped (From k v) = From k (Proxy v)

bitraverseFrom :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> From k0 v0 -> f (From k1 v1) Source #

To

type To = Maybe Source #

Describe where a key's old value will go. If this is Just, that means the key's old value will be moved to the given other key; if it is Nothing, that means it will be deleted.