Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype PatchMapWithMove k v = PatchMapWithMove {
- unPatchMapWithMove :: Map k (NodeInfo k v)
- data NodeInfo k v = NodeInfo {
- _nodeInfo_from :: !(From k v)
- _nodeInfo_to :: !(To k)
- data From k v
- = From_Insert v
- | From_Delete
- | From_Move !k
- type To = Maybe
- patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v)
- patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v
- insertMapKey :: k -> v -> PatchMapWithMove k v
- moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v
- swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v
- deleteMapKey :: k -> PatchMapWithMove k v
- unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
- patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v]
- patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v
- patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
- patchThatChangesAndSortsMapWith :: forall k v. (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v
- patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v
- nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v
- nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v)
- nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v
- data Fixup k v
- = Fixup_Delete
- | Fixup_Update (These (From k v) (To k))
Documentation
newtype PatchMapWithMove k v 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.
PatchMapWithMove | |
|
Instances
Holds the information about each key: where its new value should come from, and where its old value should go to
NodeInfo | |
|
Instances
Functor (NodeInfo k) Source # | |
Foldable (NodeInfo k) Source # | |
Defined in Data.Patch.MapWithMove 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 # | |
Traversable (NodeInfo k) Source # | |
Defined in Data.Patch.MapWithMove | |
(Eq v, Eq k) => Eq (NodeInfo k v) Source # | |
(Ord v, Ord k) => Ord (NodeInfo k v) Source # | |
Defined in Data.Patch.MapWithMove | |
(Read v, Read k) => Read (NodeInfo k v) Source # | |
(Show v, Show k) => Show (NodeInfo k v) Source # | |
Describe how a key's new value should be produced
From_Insert v | Insert the given value here |
From_Delete | Delete the existing value, if any, from here |
From_Move !k | Move the value here from the given key |
Instances
Functor (From k) Source # | |
Foldable (From k) Source # | |
Defined in Data.Patch.MapWithMove fold :: Monoid m => From k m -> m # foldMap :: Monoid m => (a -> m) -> From k a -> m # foldr :: (a -> b -> b) -> b -> From k a -> b # foldr' :: (a -> b -> b) -> b -> From k a -> b # foldl :: (b -> a -> b) -> b -> From k a -> b # foldl' :: (b -> a -> b) -> b -> From k a -> b # foldr1 :: (a -> a -> a) -> From k a -> a # foldl1 :: (a -> a -> a) -> From k a -> a # elem :: Eq a => a -> From k a -> Bool # maximum :: Ord a => From k a -> a # minimum :: Ord a => From k a -> a # | |
Traversable (From k) Source # | |
(Eq v, Eq k) => Eq (From k v) Source # | |
(Ord v, Ord k) => Ord (From k v) Source # | |
Defined in Data.Patch.MapWithMove | |
(Read v, Read k) => Read (From k v) Source # | |
(Show v, Show k) => Show (From k v) Source # | |
patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v) Source #
Create a PatchMapWithMove
, validating it
patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v Source #
Create a PatchMapWithMove
that inserts everything in the given Map
insertMapKey :: k -> v -> PatchMapWithMove k v Source #
Make a
which has the effect of inserting or updating a value PatchMapWithMove
k vv
to the given key k
, like insert
.
moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v Source #
Make a
which has the effect of moving the value from the first key PatchMapWithMove
k vk
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
which has the effect of swapping two keys in the mapping, equivalent to:PatchMapWithMove
k v
let aMay = Map.lookup a map bMay = Map.lookup b map in maybe id (Map.insert a) (bMaymplus
aMay) . maybe id (Map.insert b) (aMaymplus
bMay) . Map.delete a . Map.delete b $ map
deleteMapKey :: k -> PatchMapWithMove k v Source #
Make a
which has the effect of deleting a key in the mapping, equivalent to PatchMapWithMove
k vdelete
.
unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v Source #
Wrap a
representing patch changes into a Map
k (NodeInfo k v)
, without checking any invariants.PatchMapWithMove
k v
Warning: when using this function, you must ensure that the invariants of PatchMapWithMove
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
with all the inserts/updates from the given Map
k v
.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 :: forall k v. (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
.
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
Helper data structure used for composing patches using the monoid instance.
Fixup_Delete | |
Fixup_Update (These (From k v) (To k)) |