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

Data.Patch.MapWithMove

Contents

Description

Patches on Map that can insert, delete, and 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' FieldsunPatchMapWithMove' :: PatchMapWithPatchingMove k (Proxy v)Extract the underlying 'PatchMapWithPatchingMove k (Proxy v)'

Bundled Patterns

 pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Patch.MapWithMove Methodsimap :: (k -> a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #imapped :: IndexedSetter k (PatchMapWithMove k a) (PatchMapWithMove k b) a b # Source # Instance detailsDefined in Data.Patch.MapWithMove MethodsifoldMap :: 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 # Source # Instance detailsDefined in Data.Patch.MapWithMove Methodsitraverse :: Applicative f => (k -> a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b) #itraversed :: IndexedTraversal k (PatchMapWithMove k a) (PatchMapWithMove k b) a b # Source # Instance detailsDefined in Data.Patch.MapWithMove Methodsfmap :: (a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b #(<$) :: a -> PatchMapWithMove k b -> PatchMapWithMove k a # Source # Instance detailsDefined in Data.Patch.MapWithMove Methodsfold :: Monoid m => PatchMapWithMove k m -> m #foldMap :: Monoid m => (a -> m) -> PatchMapWithMove k a -> 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 # Source # Instance detailsDefined in Data.Patch.MapWithMove Methodstraverse :: 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 detailsDefined in Data.Patch.MapWithMove Methods(==) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool #(/=) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool # (Ord k, Ord v) => Ord (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove Methodscompare :: PatchMapWithMove k v -> PatchMapWithMove k v -> Ordering #(<) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool #(<=) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool #(>) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool #(>=) :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool #max :: PatchMapWithMove k v -> PatchMapWithMove k v -> PatchMapWithMove k v #min :: PatchMapWithMove k v -> PatchMapWithMove k v -> PatchMapWithMove k v # (Ord k, Read k, Read v) => Read (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove MethodsreadsPrec :: Int -> ReadS (PatchMapWithMove k v) # (Show k, Show v) => Show (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove MethodsshowsPrec :: Int -> PatchMapWithMove k v -> ShowS #show :: PatchMapWithMove k v -> String #showList :: [PatchMapWithMove k v] -> ShowS # 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 detailsDefined in Data.Patch.MapWithMove Methods(<>) :: PatchMapWithMove k v -> PatchMapWithMove k v -> PatchMapWithMove k v #sconcat :: NonEmpty (PatchMapWithMove k v) -> PatchMapWithMove k v #stimes :: Integral b => b -> PatchMapWithMove k v -> PatchMapWithMove k v # Ord k => Monoid (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove Methodsmappend :: PatchMapWithMove k v -> PatchMapWithMove k v -> PatchMapWithMove k v #mconcat :: [PatchMapWithMove k v] -> PatchMapWithMove k v # Source # Instance detailsDefined in Data.Patch.MapWithMove Associated Typestype Unwrapped (PatchMapWithMove k v) # Methods_Wrapped' :: Iso' (PatchMapWithMove k v) (Unwrapped (PatchMapWithMove k v)) # Ord k => Patch (PatchMapWithMove k v) Source # Apply the insertions, deletions, and moves to a given Map Instance detailsDefined in Data.Patch.MapWithMove Associated Typestype PatchTarget (PatchMapWithMove k v) Source # Methodsapply :: PatchMapWithMove k v -> PatchTarget (PatchMapWithMove k v) -> Maybe (PatchTarget (PatchMapWithMove k v)) Source # PatchMapWithMove k1 v1 ~ t => Rewrapped (PatchMapWithMove k2 v2) t Source # Instance detailsDefined in Data.Patch.MapWithMove type Unwrapped (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove type Unwrapped (PatchMapWithMove k v) = PatchMapWithPatchingMove k (Proxy v) type PatchTarget (PatchMapWithMove k v) Source # Instance detailsDefined in Data.Patch.MapWithMove type PatchTarget (PatchMapWithMove k v) = Map k v patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v) Source # Create a PatchMapWithMove, validating it Create a PatchMapWithMove that inserts everything in the given Map insertMapKey :: k -> v -> PatchMapWithMove k v Source # Make a PatchMapWithMove 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 PatchMapWithMove 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 PatchMapWithMove 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 PatchMapWithMove 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 PatchMapWithMove k v, without checking any invariants.

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

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

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

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

Create a PatchMapWithMove 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 PatchMapWithMove 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 PatchMapWithMove 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' FieldsunNodeInfo' :: NodeInfo k (Proxy v)

Bundled Patterns

 pattern NodeInfo :: To k -> From k v -> NodeInfo k v

#### Instances

Instances details

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 NodeInfo

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

Change the From value of a NodeInfo, 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 NodeInfo

# From

newtype From k (v :: Type) Source #

Describe how a key's new value should be produced

Constructors

 From' FieldsunFrom' :: From k (Proxy v)

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

Instances details
 Wrapped (From k v) Source # Instance detailsDefined in Data.Patch.MapWithMove Associated Typestype Unwrapped (From k v) # Methods_Wrapped' :: Iso' (From k v) (Unwrapped (From k v)) # From k1 v1 ~ t => Rewrapped (From k2 v2) t Source # Instance detailsDefined in Data.Patch.MapWithMove type Unwrapped (From k v) Source # Instance detailsDefined 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.