Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Patches of this type can insert, delete, and also move values from one key to another.
Synopsis
- newtype PatchMapWithMove k (v :: Type) where
- PatchMapWithMove' { }
- pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
- 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 :: (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
- newtype NodeInfo k (v :: Type) where
- bitraverseNodeInfo :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> NodeInfo k0 v0 -> f (NodeInfo k1 v1)
- 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
- newtype From k (v :: Type) where
- From' { }
- pattern From_Insert :: v -> From k v
- pattern From_Delete :: From k v
- pattern From_Move :: k -> From k v
- bitraverseFrom :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> From k0 v0 -> f (From k1 v1)
- type To = Maybe
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.
PatchMapWithMove' | |
|
pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v |
Instances
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) (bMay <> aMay) . maybe id (Map.insert b) (aMay <> 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 :: (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
NodeInfo' | |
|
Instances
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 # 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 | |
Functor (NodeInfo k) Source # | |
(Read k, Read p) => Read (NodeInfo k p) Source # | |
(Show k, Show p) => Show (NodeInfo k p) Source # | |
(Eq k, Eq p) => Eq (NodeInfo k p) Source # | |
(Ord k, Ord p) => Ord (NodeInfo k p) Source # | |
Defined in Data.Patch.MapWithMove | |
Wrapped (NodeInfo k v) Source # | |
NodeInfo k1 v1 ~ t => Rewrapped (NodeInfo k2 v2) t Source # | |
Defined in Data.Patch.MapWithMove | |
type Unwrapped (NodeInfo k v) Source # | |
Defined in Data.Patch.MapWithMove |
bitraverseNodeInfo :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> NodeInfo k0 v0 -> f (NodeInfo k1 v1) Source #
Like bitraverse
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
From
newtype From k (v :: Type) Source #
Describe how a key's new value should be produced
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 |
bitraverseFrom :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) -> From k0 v0 -> f (From k1 v1) Source #
Like bitraverse