Safe Haskell | None |
---|---|
Language | Haskell2010 |
Module containing
and associated functions, which represents a PatchDMapWithMove
k vPatch
to a
which can insert, update, delete, and
move values between keys.DMap
k v
Synopsis
- newtype PatchDMapWithMove k v = PatchDMapWithMove (DMap k (NodeInfo k v))
- data NodeInfo k v a = NodeInfo {
- _nodeInfo_from :: !(From k v a)
- _nodeInfo_to :: !(To k a)
- data From (k :: a -> *) (v :: a -> *) :: a -> * where
- From_Insert :: v a -> From k v a
- From_Delete :: From k v a
- From_Move :: !(k a) -> From k v a
- type To = ComposeMaybe
- validPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Bool
- validationErrorsForPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> [String]
- data Pair1 f g a = Pair1 (f a) (g a)
- data Fixup k v a
- = Fixup_Delete
- | Fixup_Update (These (From k v a) (To k a))
- insertDMapKey :: k a -> v a -> PatchDMapWithMove k v
- moveDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v
- swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v
- deleteDMapKey :: k a -> PatchDMapWithMove k v
- unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v)
- unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v
- patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v)
- mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v'
- traversePatchDMapWithMove :: forall m k v v'. Applicative m => (forall a. v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v')
- traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v')
- nodeInfoMapFrom :: (From k v a -> From k v' a) -> NodeInfo k v a -> NodeInfo k v' a
- nodeInfoMapFromM :: Functor f => (From k v a -> f (From k v' a)) -> NodeInfo k v a -> f (NodeInfo k v' a)
- weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) v'
- patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k v'
- const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k v -> PatchDMapWithMove (Const2 k a) v'
- getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k))
Documentation
newtype PatchDMapWithMove k v Source #
Like PatchMapWithMove
, but for DMap
. Each key carries a NodeInfo
which describes how it will be changed by the patch and connects move sources and
destinations.
Invariants:
- A key should not move to itself.
- A move should always be represented with both the destination key (as a
From_Move
) and the source key (as a
)ComposeMaybe
(Just
destination)
PatchDMapWithMove (DMap k (NodeInfo k v)) |
Instances
Structure which represents what changes apply to a particular key. _nodeInfo_from
specifies what happens to this key, and in particular what other key
the current key is moving from, while _nodeInfo_to
specifies what key the current key is moving to if involved in a move.
NodeInfo | |
|
data From (k :: a -> *) (v :: a -> *) :: a -> * where Source #
Structure describing a particular change to a key, be it inserting a new key (From_Insert
), updating an existing key (From_Insert
again), deleting a
key (From_Delete
), or moving a key (From_Move
).
From_Insert :: v a -> From k v a | Insert a new or update an existing key with the given value |
From_Delete :: From k v a | Delete the existing key |
From_Move :: !(k a) -> From k v a | Move the value from the given key |
Instances
(Eq (v b), Eq (k b)) => Eq (From k v b) Source # | |
(Ord (v b), Ord (k b)) => Ord (From k v b) Source # | |
(Read (v b), Read (k b)) => Read (From k v b) Source # | |
(Show (v b), Show (k b)) => Show (From k v b) Source # | |
type To = ComposeMaybe Source #
Type alias for the "to" part of a NodeInfo
.
means the key is moving to another key, ComposeMaybe
(Just
k)ComposeMaybe Nothing
for any other
operation.
validPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Bool Source #
Test whether a PatchDMapWithMove
satisfies its invariants.
validationErrorsForPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> [String] Source #
Enumerate what reasons a PatchDMapWithMove
doesn't satisfy its invariants, returning []
if it's valid.
Higher kinded 2-tuple, identical to Data.Functor.Product
from base ≥ 4.9
Pair1 (f a) (g a) |
Helper data structure used for composing patches using the monoid instance.
Fixup_Delete | |
Fixup_Update (These (From k v a) (To k a)) |
insertDMapKey :: k a -> v a -> PatchDMapWithMove k v Source #
Make a
which has the effect of inserting or updating a value PatchDMapWithMove
k vv a
to the given key k a
, like insert
.
moveDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v Source #
Make a
which has the effect of moving the value from the first key PatchDMapWithMove
k vk a
to the second key k a
, equivalent to:
delete
src (maybe dmap (insert
dst) (DMap.lookup src dmap))
swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v Source #
Make a
which has the effect of swapping two keys in the mapping, equivalent to:PatchDMapWithMove
k v
let aMay = DMap.lookup a dmap bMay = DMap.lookup b dmap in maybe id (DMap.insert a) (bMaymplus
aMay) . maybe id (DMap.insert b) (aMaymplus
bMay) . DMap.delete a . DMap.delete b $ dmap
deleteDMapKey :: k a -> PatchDMapWithMove k v Source #
Make a
which has the effect of deleting a key in the mapping, equivalent to PatchDMapWithMove
k vdelete
.
unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v) Source #
Extract the DMap
representing the patch changes from the PatchDMapWithMove
.
unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v Source #
Wrap a DMap
representing patch changes into a PatchDMapWithMove
, without checking any invariants.
Warning: when using this function, you must ensure that the invariants of PatchDMapWithMove
are preserved; they will not be checked.
patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v) Source #
Wrap a DMap
representing patch changes into a PatchDMapWithMove
while checking invariants. If the invariants are satisfied, Right p
is returned
otherwise Left errors
.
mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v' Source #
Map a natural transform v -> v'
over the given patch, transforming
into PatchDMapWithMove
k v
.PatchDMapWithMove
k v'
traversePatchDMapWithMove :: forall m k v v'. Applicative m => (forall a. v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') Source #
Traverse an effectful function forall a. v a -> m (v ' a)
over the given patch, transforming
into PatchDMapWithMove
k vm (
.PatchDMapWithMove
k v')
traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') Source #
Map an effectful function forall a. k a -> v a -> m (v ' a)
over the given patch, transforming
into PatchDMapWithMove
k vm (
.PatchDMapWithMove
k v')
nodeInfoMapFromM :: Functor f => (From k v a -> f (From k v' a)) -> NodeInfo k v a -> f (NodeInfo k v' a) Source #
weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) v' Source #
Weaken a PatchDMapWithMove
to a PatchMapWithMove
by weakening the keys from k a
to
and applying a given weakening function Some
kv a -> v'
to
values.
patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k v' Source #
Weaken a
to a PatchDMapWithMove
(Const2 k a) v
. Weaken is in scare quotes because the PatchMapWithMove
k v'Const2
has already disabled any
dependency in the typing and all points are already a
, hence the function to map each value to v'
is not higher rank.
const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k v -> PatchDMapWithMove (Const2 k a) v' Source #
Strengthen a
into a PatchMapWithMove
k v'PatchDMapWithMove (
; that is, turn a non-dependently-typed patch into a dependently typed
one but which always has a constant key type represented by Const2
k a)Const2
. Apply the given function to each v
to produce a v' a
.
Completemented by patchDMapWithMoveToPatchMapWithMoveWith
getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k)) Source #
Get the values that will be replaced, deleted, or moved if the given patch is applied to the given DMap
.