| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Patch.DMapWithMove
Description
This Module contains 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 (k1 :: k -> Type) (v :: k -> Type) = PatchDMapWithMove (DMap k1 (NodeInfo k1 v))
- data NodeInfo (k1 :: k -> Type) (v :: k -> Type) (a :: k) = NodeInfo {
- _nodeInfo_from :: !(From k1 v a)
- _nodeInfo_to :: !(To k1 a)
- data From (k :: a -> Type) (v :: a -> Type) (b :: a) where
- type To = ComposeMaybe :: (k -> Type) -> k -> Type
- validPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> Bool
- validationErrorsForPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> [String]
- data Pair1 (f :: k -> Type) (g :: k -> Type) (a :: k) = Pair1 (f a) (g a)
- data Fixup (k1 :: k -> Type) (v :: k -> Type) (a :: k)
- = Fixup_Delete
- | Fixup_Update (These (From k1 v a) (To k1 a))
- insertDMapKey :: forall {k1} k2 (a :: k1) v. k2 a -> v a -> PatchDMapWithMove k2 v
- moveDMapKey :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). GCompare k2 => k2 a -> k2 a -> PatchDMapWithMove k2 v
- swapDMapKey :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). GCompare k2 => k2 a -> k2 a -> PatchDMapWithMove k2 v
- deleteDMapKey :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). k2 a -> PatchDMapWithMove k2 v
- unPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). PatchDMapWithMove k2 v -> DMap k2 (NodeInfo k2 v)
- unsafePatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). DMap k2 (NodeInfo k2 v) -> PatchDMapWithMove k2 v
- patchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> Either [String] (PatchDMapWithMove k2 v)
- mapPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) v v'. (forall (a :: k1). v a -> v' a) -> PatchDMapWithMove k2 v -> PatchDMapWithMove k2 v'
- traversePatchDMapWithMove :: forall {k1} m (k2 :: k1 -> Type) v v'. Applicative m => (forall (a :: k1). v a -> m (v' a)) -> PatchDMapWithMove k2 v -> m (PatchDMapWithMove k2 v')
- traversePatchDMapWithMoveWithKey :: forall {k1} m k2 v v'. Applicative m => (forall (a :: k1). k2 a -> v a -> m (v' a)) -> PatchDMapWithMove k2 v -> m (PatchDMapWithMove k2 v')
- nodeInfoMapFrom :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type) (a :: k1) (v' :: k1 -> Type). (From k2 v a -> From k2 v' a) -> NodeInfo k2 v a -> NodeInfo k2 v' a
- nodeInfoMapFromM :: forall {k1} f (k2 :: k1 -> Type) (v :: k1 -> Type) (a :: k1) (v' :: k1 -> Type). Functor f => (From k2 v a -> f (From k2 v' a)) -> NodeInfo k2 v a -> f (NodeInfo k2 v' a)
- weakenPatchDMapWithMoveWith :: forall {k1} (k2 :: k1 -> Type) v v'. (forall (a :: k1). v a -> v') -> PatchDMapWithMove k2 v -> PatchMapWithMove (Some k2) v'
- patchDMapWithMoveToPatchMapWithMoveWith :: forall {k1} k2 v v' (a :: k1). (v a -> v') -> PatchDMapWithMove (Const2 k2 a) v -> PatchMapWithMove k2 v'
- const2PatchDMapWithMoveWith :: forall {k1} k2 v v' (a :: k1). (v -> v' a) -> PatchMapWithMove k2 v -> PatchDMapWithMove (Const2 k2 a) v'
- getDeletionsAndMoves :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type) (v' :: k1 -> Type). GCompare k2 => PatchDMapWithMove k2 v -> DMap k2 v' -> DMap k2 (Product v' (ComposeMaybe k2))
Documentation
newtype PatchDMapWithMove (k1 :: k -> Type) (v :: k -> Type) 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(Justdestination)
Constructors
| PatchDMapWithMove (DMap k1 (NodeInfo k1 v)) |
Instances
data NodeInfo (k1 :: k -> Type) (v :: k -> Type) (a :: k) Source #
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.
Constructors
| NodeInfo | |
Fields
| |
data From (k :: a -> Type) (v :: a -> Type) (b :: 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).
Constructors
| From_Insert :: forall {a} (v :: a -> Type) (b :: a) (k :: a -> Type). v b -> From k v b | Insert a new or update an existing key with the given value |
| From_Delete :: forall {a} (k :: a -> Type) (v :: a -> Type) (b :: a). From k v b | Delete the existing key |
| From_Move :: forall {a} (k :: a -> Type) (b :: a) (v :: a -> Type). !(k b) -> From k v b | Move the value from the given key |
Instances
| (Read (v b), Read (k b)) => Read (From k v b) Source # | |
| (Show (v b), Show (k b)) => Show (From k v b) Source # | |
| (Eq (v b), Eq (k b)) => Eq (From k v b) Source # | |
| (Ord (v b), Ord (k b)) => Ord (From k v b) Source # | |
Defined in Data.Patch.DMapWithMove | |
type To = ComposeMaybe :: (k -> Type) -> k -> Type 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 {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> Bool Source #
Test whether a PatchDMapWithMove satisfies its invariants.
validationErrorsForPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> [String] Source #
Enumerate what reasons a PatchDMapWithMove doesn't satisfy its invariants, returning [] if it's valid.
data Pair1 (f :: k -> Type) (g :: k -> Type) (a :: k) Source #
Higher kinded 2-tuple, identical to Data.Functor.Product from base ≥ 4.9
Constructors
| Pair1 (f a) (g a) |
data Fixup (k1 :: k -> Type) (v :: k -> Type) (a :: k) Source #
Helper data structure used for composing patches using the monoid instance.
Constructors
| Fixup_Delete | |
| Fixup_Update (These (From k1 v a) (To k1 a)) |
insertDMapKey :: forall {k1} k2 (a :: k1) v. k2 a -> v a -> PatchDMapWithMove k2 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 :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). GCompare k2 => k2 a -> k2 a -> PatchDMapWithMove k2 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:
deletesrc (maybe dmap (insertdst) (DMap.lookup src dmap))
swapDMapKey :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). GCompare k2 => k2 a -> k2 a -> PatchDMapWithMove k2 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) (bMay <> aMay)
. maybe id (DMap.insert b) (aMay <> bMay)
. DMap.delete a . DMap.delete b $ dmap
deleteDMapKey :: forall {k1} k2 (a :: k1) (v :: k1 -> Type). k2 a -> PatchDMapWithMove k2 v Source #
Make a which has the effect of deleting a key in the mapping, equivalent to PatchDMapWithMove k vdelete.
unPatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). PatchDMapWithMove k2 v -> DMap k2 (NodeInfo k2 v) Source #
Extract the DMap representing the patch changes from the PatchDMapWithMove.
unsafePatchDMapWithMove :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). DMap k2 (NodeInfo k2 v) -> PatchDMapWithMove k2 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 :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type). (GCompare k2, GShow k2) => DMap k2 (NodeInfo k2 v) -> Either [String] (PatchDMapWithMove k2 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 {k1} (k2 :: k1 -> Type) v v'. (forall (a :: k1). v a -> v' a) -> PatchDMapWithMove k2 v -> PatchDMapWithMove k2 v' Source #
Map a natural transform v -> v' over the given patch, transforming into PatchDMapWithMove k v.PatchDMapWithMove k v'
traversePatchDMapWithMove :: forall {k1} m (k2 :: k1 -> Type) v v'. Applicative m => (forall (a :: k1). v a -> m (v' a)) -> PatchDMapWithMove k2 v -> m (PatchDMapWithMove k2 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 {k1} m k2 v v'. Applicative m => (forall (a :: k1). k2 a -> v a -> m (v' a)) -> PatchDMapWithMove k2 v -> m (PatchDMapWithMove k2 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')
nodeInfoMapFrom :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type) (a :: k1) (v' :: k1 -> Type). (From k2 v a -> From k2 v' a) -> NodeInfo k2 v a -> NodeInfo k2 v' a Source #
nodeInfoMapFromM :: forall {k1} f (k2 :: k1 -> Type) (v :: k1 -> Type) (a :: k1) (v' :: k1 -> Type). Functor f => (From k2 v a -> f (From k2 v' a)) -> NodeInfo k2 v a -> f (NodeInfo k2 v' a) Source #
weakenPatchDMapWithMoveWith :: forall {k1} (k2 :: k1 -> Type) v v'. (forall (a :: k1). v a -> v') -> PatchDMapWithMove k2 v -> PatchMapWithMove (Some k2) 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 {k1} k2 v v' (a :: k1). (v a -> v') -> PatchDMapWithMove (Const2 k2 a) v -> PatchMapWithMove k2 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 {k1} k2 v v' (a :: k1). (v -> v' a) -> PatchMapWithMove k2 v -> PatchDMapWithMove (Const2 k2 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 :: forall {k1} (k2 :: k1 -> Type) (v :: k1 -> Type) (v' :: k1 -> Type). GCompare k2 => PatchDMapWithMove k2 v -> DMap k2 v' -> DMap k2 (Product v' (ComposeMaybe k2)) Source #
Get the values that will be replaced, deleted, or moved if the given patch is applied to the given DMap.