{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Patch.MapWithMove
( PatchMapWithMove
( PatchMapWithMove
, unPatchMapWithMove
, ..
)
, patchMapWithMove
, patchMapWithMoveInsertAll
, insertMapKey
, moveMapKey
, swapMapKey
, deleteMapKey
, unsafePatchMapWithMove
, patchMapWithMoveNewElements
, patchMapWithMoveNewElementsMap
, patchThatSortsMapWith
, patchThatChangesAndSortsMapWith
, patchThatChangesMap
, NodeInfo
( NodeInfo
, _nodeInfo_to
, _nodeInfo_from
, ..
)
, bitraverseNodeInfo
, nodeInfoMapFrom
, nodeInfoMapMFrom
, nodeInfoSetTo
, From
( From_Insert
, From_Delete
, From_Move
, ..
)
, bitraverseFrom
, To
) where
import Data.Coerce
import Data.Kind (Type)
import Data.Patch.Class
import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove(..), To)
import qualified Data.Patch.MapWithPatchingMove as PM
import Control.Lens
import Data.List
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Proxy
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup (Semigroup (..))
#endif
import Data.Traversable (foldMapDefault)
newtype PatchMapWithMove k (v :: Type) = PatchMapWithMove'
{
PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v)
unPatchMapWithMove' :: PatchMapWithPatchingMove k (Proxy v)
}
deriving ( Int -> PatchMapWithMove k v -> ShowS
[PatchMapWithMove k v] -> ShowS
PatchMapWithMove k v -> String
(Int -> PatchMapWithMove k v -> ShowS)
-> (PatchMapWithMove k v -> String)
-> ([PatchMapWithMove k v] -> ShowS)
-> Show (PatchMapWithMove k v)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k v.
(Show k, Show v) =>
Int -> PatchMapWithMove k v -> ShowS
forall k v. (Show k, Show v) => [PatchMapWithMove k v] -> ShowS
forall k v. (Show k, Show v) => PatchMapWithMove k v -> String
showList :: [PatchMapWithMove k v] -> ShowS
$cshowList :: forall k v. (Show k, Show v) => [PatchMapWithMove k v] -> ShowS
show :: PatchMapWithMove k v -> String
$cshow :: forall k v. (Show k, Show v) => PatchMapWithMove k v -> String
showsPrec :: Int -> PatchMapWithMove k v -> ShowS
$cshowsPrec :: forall k v.
(Show k, Show v) =>
Int -> PatchMapWithMove k v -> ShowS
Show, ReadPrec [PatchMapWithMove k v]
ReadPrec (PatchMapWithMove k v)
Int -> ReadS (PatchMapWithMove k v)
ReadS [PatchMapWithMove k v]
(Int -> ReadS (PatchMapWithMove k v))
-> ReadS [PatchMapWithMove k v]
-> ReadPrec (PatchMapWithMove k v)
-> ReadPrec [PatchMapWithMove k v]
-> Read (PatchMapWithMove k v)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k v.
(Ord k, Read k, Read v) =>
ReadPrec [PatchMapWithMove k v]
forall k v.
(Ord k, Read k, Read v) =>
ReadPrec (PatchMapWithMove k v)
forall k v.
(Ord k, Read k, Read v) =>
Int -> ReadS (PatchMapWithMove k v)
forall k v. (Ord k, Read k, Read v) => ReadS [PatchMapWithMove k v]
readListPrec :: ReadPrec [PatchMapWithMove k v]
$creadListPrec :: forall k v.
(Ord k, Read k, Read v) =>
ReadPrec [PatchMapWithMove k v]
readPrec :: ReadPrec (PatchMapWithMove k v)
$creadPrec :: forall k v.
(Ord k, Read k, Read v) =>
ReadPrec (PatchMapWithMove k v)
readList :: ReadS [PatchMapWithMove k v]
$creadList :: forall k v. (Ord k, Read k, Read v) => ReadS [PatchMapWithMove k v]
readsPrec :: Int -> ReadS (PatchMapWithMove k v)
$creadsPrec :: forall k v.
(Ord k, Read k, Read v) =>
Int -> ReadS (PatchMapWithMove k v)
Read, PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
(PatchMapWithMove k v -> PatchMapWithMove k v -> Bool)
-> (PatchMapWithMove k v -> PatchMapWithMove k v -> Bool)
-> Eq (PatchMapWithMove k v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k v.
(Eq k, Eq v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
/= :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c/= :: forall k v.
(Eq k, Eq v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
== :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c== :: forall k v.
(Eq k, Eq v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
Eq, Eq (PatchMapWithMove k v)
Eq (PatchMapWithMove k v)
-> (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)
-> (PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v)
-> (PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v)
-> Ord (PatchMapWithMove k v)
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
PatchMapWithMove k v -> PatchMapWithMove k v -> Ordering
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k v. (Ord k, Ord v) => Eq (PatchMapWithMove k v)
forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Ordering
forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
min :: PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
$cmin :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
max :: PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
$cmax :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
>= :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c>= :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
> :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c> :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
<= :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c<= :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
< :: PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
$c< :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Bool
compare :: PatchMapWithMove k v -> PatchMapWithMove k v -> Ordering
$ccompare :: forall k v.
(Ord k, Ord v) =>
PatchMapWithMove k v -> PatchMapWithMove k v -> Ordering
$cp1Ord :: forall k v. (Ord k, Ord v) => Eq (PatchMapWithMove k v)
Ord
,
#if __GLASGOW_HASKELL__ >= 806
#endif
Semigroup
, Semigroup (PatchMapWithMove k v)
PatchMapWithMove k v
Semigroup (PatchMapWithMove k v)
-> PatchMapWithMove k v
-> (PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v)
-> ([PatchMapWithMove k v] -> PatchMapWithMove k v)
-> Monoid (PatchMapWithMove k v)
[PatchMapWithMove k v] -> PatchMapWithMove k v
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall k v. Ord k => Semigroup (PatchMapWithMove k v)
forall k v. Ord k => PatchMapWithMove k v
forall k v. Ord k => [PatchMapWithMove k v] -> PatchMapWithMove k v
forall k v.
Ord k =>
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
mconcat :: [PatchMapWithMove k v] -> PatchMapWithMove k v
$cmconcat :: forall k v. Ord k => [PatchMapWithMove k v] -> PatchMapWithMove k v
mappend :: PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
$cmappend :: forall k v.
Ord k =>
PatchMapWithMove k v
-> PatchMapWithMove k v -> PatchMapWithMove k v
mempty :: PatchMapWithMove k v
$cmempty :: forall k v. Ord k => PatchMapWithMove k v
$cp1Monoid :: forall k v. Ord k => Semigroup (PatchMapWithMove k v)
Monoid
)
pattern Coerce :: Coercible a b => a -> b
pattern $bCoerce :: a -> b
$mCoerce :: forall r a b. Coercible a b => b -> (a -> r) -> (Void# -> r) -> r
Coerce x <- (coerce -> x)
where Coerce a
x = a -> b
coerce a
x
{-# COMPLETE PatchMapWithMove #-}
pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo k v)
pattern $bPatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
$mPatchMapWithMove :: forall r k v.
PatchMapWithMove k v
-> (Map k (NodeInfo k v) -> r) -> (Void# -> r) -> r
PatchMapWithMove { PatchMapWithMove k v -> Map k (NodeInfo k v)
unPatchMapWithMove } = PatchMapWithMove' (PatchMapWithPatchingMove (Coerce unPatchMapWithMove))
_PatchMapWithMove
:: Iso
(PatchMapWithMove k0 v0)
(PatchMapWithMove k1 v1)
(Map k0 (NodeInfo k0 v0))
(Map k1 (NodeInfo k1 v1))
_PatchMapWithMove :: p (Map k0 (NodeInfo k0 v0)) (f (Map k1 (NodeInfo k1 v1)))
-> p (PatchMapWithMove k0 v0) (f (PatchMapWithMove k1 v1))
_PatchMapWithMove = (PatchMapWithMove k0 v0 -> Map k0 (NodeInfo k0 v0))
-> (Map k1 (NodeInfo k1 v1) -> PatchMapWithMove k1 v1)
-> Iso
(PatchMapWithMove k0 v0)
(PatchMapWithMove k1 v1)
(Map k0 (NodeInfo k0 v0))
(Map k1 (NodeInfo k1 v1))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso PatchMapWithMove k0 v0 -> Map k0 (NodeInfo k0 v0)
forall k v. PatchMapWithMove k v -> Map k (NodeInfo k v)
unPatchMapWithMove Map k1 (NodeInfo k1 v1) -> PatchMapWithMove k1 v1
forall k v. Map k (NodeInfo k v) -> PatchMapWithMove k v
PatchMapWithMove
instance Functor (PatchMapWithMove k) where
fmap :: (a -> b) -> PatchMapWithMove k a -> PatchMapWithMove k b
fmap a -> b
f = Identity (PatchMapWithMove k b) -> PatchMapWithMove k b
forall a. Identity a -> a
runIdentity (Identity (PatchMapWithMove k b) -> PatchMapWithMove k b)
-> (PatchMapWithMove k a -> Identity (PatchMapWithMove k b))
-> PatchMapWithMove k a
-> PatchMapWithMove k b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Identity b)
-> PatchMapWithMove k a -> Identity (PatchMapWithMove k b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b) -> (a -> b) -> a -> Identity b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
instance Foldable (PatchMapWithMove k) where
foldMap :: (a -> m) -> PatchMapWithMove k a -> m
foldMap = (a -> m) -> PatchMapWithMove k a -> m
forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance Traversable (PatchMapWithMove k) where
traverse :: (a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b)
traverse =
(Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> PatchMapWithMove k a -> f (PatchMapWithMove k b)
forall k0 v0 k1 v1.
Iso
(PatchMapWithMove k0 v0)
(PatchMapWithMove k1 v1)
(Map k0 (NodeInfo k0 v0))
(Map k1 (NodeInfo k1 v1))
_PatchMapWithMove ((Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> PatchMapWithMove k a -> f (PatchMapWithMove k b))
-> ((a -> f b) -> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> (a -> f b)
-> PatchMapWithMove k a
-> f (PatchMapWithMove k b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(NodeInfo k a -> f (NodeInfo k b))
-> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((NodeInfo k a -> f (NodeInfo k b))
-> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> ((a -> f b) -> NodeInfo k a -> f (NodeInfo k b))
-> (a -> f b)
-> Map k (NodeInfo k a)
-> f (Map k (NodeInfo k b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(a -> f b) -> NodeInfo k a -> f (NodeInfo k b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
instance FunctorWithIndex k (PatchMapWithMove k)
instance FoldableWithIndex k (PatchMapWithMove k)
instance TraversableWithIndex k (PatchMapWithMove k) where
itraverse :: (k -> a -> f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b)
itraverse = Indexed k a (f b)
-> PatchMapWithMove k a -> f (PatchMapWithMove k b)
forall i (t :: * -> *) a b.
TraversableWithIndex i t =>
IndexedTraversal i (t a) (t b) a b
itraversed (Indexed k a (f b)
-> PatchMapWithMove k a -> f (PatchMapWithMove k b))
-> ((k -> a -> f b) -> Indexed k a (f b))
-> (k -> a -> f b)
-> PatchMapWithMove k a
-> f (PatchMapWithMove k b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k -> a -> f b) -> Indexed k a (f b)
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed
itraversed :: p a (f b) -> PatchMapWithMove k a -> f (PatchMapWithMove k b)
itraversed =
(Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> PatchMapWithMove k a -> f (PatchMapWithMove k b)
forall k0 v0 k1 v1.
Iso
(PatchMapWithMove k0 v0)
(PatchMapWithMove k1 v1)
(Map k0 (NodeInfo k0 v0))
(Map k1 (NodeInfo k1 v1))
_PatchMapWithMove ((Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> PatchMapWithMove k a -> f (PatchMapWithMove k b))
-> (p a (f b) -> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> p a (f b)
-> PatchMapWithMove k a
-> f (PatchMapWithMove k b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.>
Indexed k (NodeInfo k a) (f (NodeInfo k b))
-> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b))
forall i (t :: * -> *) a b.
TraversableWithIndex i t =>
IndexedTraversal i (t a) (t b) a b
itraversed (Indexed k (NodeInfo k a) (f (NodeInfo k b))
-> Map k (NodeInfo k a) -> f (Map k (NodeInfo k b)))
-> ((a -> f b) -> NodeInfo k a -> f (NodeInfo k b))
-> p a (f b)
-> Map k (NodeInfo k a)
-> f (Map k (NodeInfo k b))
forall i (p :: * -> * -> *) s t r a b.
Indexable i p =>
(Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r
<.
(a -> f b) -> NodeInfo k a -> f (NodeInfo k b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v)
patchMapWithMove :: Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v)
patchMapWithMove = (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> Maybe (PatchMapWithPatchingMove k (Proxy v))
-> Maybe (PatchMapWithMove k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (Maybe (PatchMapWithPatchingMove k (Proxy v))
-> Maybe (PatchMapWithMove k v))
-> (Map k (NodeInfo k v)
-> Maybe (PatchMapWithPatchingMove k (Proxy v)))
-> Map k (NodeInfo k v)
-> Maybe (PatchMapWithMove k v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (NodeInfo k (Proxy v))
-> Maybe (PatchMapWithPatchingMove k (Proxy v))
forall k p.
Ord k =>
Map k (NodeInfo k p) -> Maybe (PatchMapWithPatchingMove k p)
PM.patchMapWithPatchingMove (Map k (NodeInfo k (Proxy v))
-> Maybe (PatchMapWithPatchingMove k (Proxy v)))
-> (Map k (NodeInfo k v) -> Map k (NodeInfo k (Proxy v)))
-> Map k (NodeInfo k v)
-> Maybe (PatchMapWithPatchingMove k (Proxy v))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k (NodeInfo k v) -> Map k (NodeInfo k (Proxy v))
coerce
patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v
patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v
patchMapWithMoveInsertAll = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> (Map k v -> PatchMapWithPatchingMove k (Proxy v))
-> Map k v
-> PatchMapWithMove k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> PatchMapWithPatchingMove k (Proxy v)
forall k p. Map k (PatchTarget p) -> PatchMapWithPatchingMove k p
PM.patchMapWithPatchingMoveInsertAll
insertMapKey :: k -> v -> PatchMapWithMove k v
insertMapKey :: k -> v -> PatchMapWithMove k v
insertMapKey k
k v
v = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall a b. (a -> b) -> a -> b
$ k -> PatchTarget (Proxy v) -> PatchMapWithPatchingMove k (Proxy v)
forall k p. k -> PatchTarget p -> PatchMapWithPatchingMove k p
PM.insertMapKey k
k v
PatchTarget (Proxy v)
v
moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v
moveMapKey :: k -> k -> PatchMapWithMove k v
moveMapKey k
src k
dst = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall a b. (a -> b) -> a -> b
$ k -> k -> PatchMapWithPatchingMove k (Proxy v)
forall p k.
(DecidablyEmpty p, Patch p, Ord k) =>
k -> k -> PatchMapWithPatchingMove k p
PM.moveMapKey k
src k
dst
swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v
swapMapKey :: k -> k -> PatchMapWithMove k v
swapMapKey k
src k
dst = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall a b. (a -> b) -> a -> b
$ k -> k -> PatchMapWithPatchingMove k (Proxy v)
forall p k.
(DecidablyEmpty p, Patch p, Ord k) =>
k -> k -> PatchMapWithPatchingMove k p
PM.swapMapKey k
src k
dst
deleteMapKey :: k -> PatchMapWithMove k v
deleteMapKey :: k -> PatchMapWithMove k v
deleteMapKey = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> (k -> PatchMapWithPatchingMove k (Proxy v))
-> k
-> PatchMapWithMove k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> PatchMapWithPatchingMove k (Proxy v)
forall k v. k -> PatchMapWithPatchingMove k v
PM.deleteMapKey
unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
unsafePatchMapWithMove = (Map k (NodeInfo k (Proxy v))
-> PatchMapWithPatchingMove k (Proxy v))
-> Map k (NodeInfo k v) -> PatchMapWithMove k v
coerce Map k (NodeInfo k (Proxy v))
-> PatchMapWithPatchingMove k (Proxy v)
forall k p. Map k (NodeInfo k p) -> PatchMapWithPatchingMove k p
PM.unsafePatchMapWithPatchingMove
instance Ord k => Patch (PatchMapWithMove k v) where
type PatchTarget (PatchMapWithMove k v) = Map k v
apply :: PatchMapWithMove k v
-> PatchTarget (PatchMapWithMove k v)
-> Maybe (PatchTarget (PatchMapWithMove k v))
apply (PatchMapWithMove' PatchMapWithPatchingMove k (Proxy v)
p) = PatchMapWithPatchingMove k (Proxy v)
-> PatchTarget (PatchMapWithPatchingMove k (Proxy v))
-> Maybe (PatchTarget (PatchMapWithPatchingMove k (Proxy v)))
forall p. Patch p => p -> PatchTarget p -> Maybe (PatchTarget p)
apply PatchMapWithPatchingMove k (Proxy v)
p
patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v]
patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v]
patchMapWithMoveNewElements = PatchMapWithPatchingMove k (Proxy v) -> [v]
forall k p. PatchMapWithPatchingMove k p -> [PatchTarget p]
PM.patchMapWithPatchingMoveNewElements (PatchMapWithPatchingMove k (Proxy v) -> [v])
-> (PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v))
-> PatchMapWithMove k v
-> [v]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v)
forall k v.
PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v)
unPatchMapWithMove'
patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v
patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v
patchMapWithMoveNewElementsMap = PatchMapWithPatchingMove k (Proxy v) -> Map k v
forall k p. PatchMapWithPatchingMove k p -> Map k (PatchTarget p)
PM.patchMapWithPatchingMoveNewElementsMap (PatchMapWithPatchingMove k (Proxy v) -> Map k v)
-> (PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v))
-> PatchMapWithMove k v
-> Map k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v)
forall k v.
PatchMapWithMove k v -> PatchMapWithPatchingMove k (Proxy v)
unPatchMapWithMove'
patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
patchThatSortsMapWith :: (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
patchThatSortsMapWith v -> v -> Ordering
cmp = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> (Map k v -> PatchMapWithPatchingMove k (Proxy v))
-> Map k v
-> PatchMapWithMove k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PatchTarget (Proxy v) -> PatchTarget (Proxy v) -> Ordering)
-> Map k (PatchTarget (Proxy v))
-> PatchMapWithPatchingMove k (Proxy v)
forall k p.
(Ord k, Monoid p) =>
(PatchTarget p -> PatchTarget p -> Ordering)
-> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p
PM.patchThatSortsMapWith v -> v -> Ordering
PatchTarget (Proxy v) -> PatchTarget (Proxy v) -> Ordering
cmp
patchThatChangesAndSortsMapWith :: (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v
patchThatChangesAndSortsMapWith :: (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v
patchThatChangesAndSortsMapWith v -> v -> Ordering
cmp Map k v
oldByIndex Map k v
newByIndexUnsorted = Map k v -> Map k v -> PatchMapWithMove k v
forall k v.
(Ord k, Ord v) =>
Map k v -> Map k v -> PatchMapWithMove k v
patchThatChangesMap Map k v
oldByIndex Map k v
newByIndex
where newList :: [(k, v)]
newList = Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toList Map k v
newByIndexUnsorted
newByIndex :: Map k v
newByIndex = [(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(k, v)] -> Map k v) -> [(k, v)] -> Map k v
forall a b. (a -> b) -> a -> b
$ [k] -> [v] -> [(k, v)]
forall a b. [a] -> [b] -> [(a, b)]
zip ((k, v) -> k
forall a b. (a, b) -> a
fst ((k, v) -> k) -> [(k, v)] -> [k]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(k, v)]
newList) ([v] -> [(k, v)]) -> [v] -> [(k, v)]
forall a b. (a -> b) -> a -> b
$ (v -> v -> Ordering) -> [v] -> [v]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy v -> v -> Ordering
cmp ([v] -> [v]) -> [v] -> [v]
forall a b. (a -> b) -> a -> b
$ (k, v) -> v
forall a b. (a, b) -> b
snd ((k, v) -> v) -> [(k, v)] -> [v]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(k, v)]
newList
patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v
patchThatChangesMap :: Map k v -> Map k v -> PatchMapWithMove k v
patchThatChangesMap Map k v
oldByIndex Map k v
newByIndex = PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall k v.
PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
PatchMapWithMove' (PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v)
-> PatchMapWithPatchingMove k (Proxy v) -> PatchMapWithMove k v
forall a b. (a -> b) -> a -> b
$
Map k (PatchTarget (Proxy v))
-> Map k (PatchTarget (Proxy v))
-> PatchMapWithPatchingMove k (Proxy v)
forall k p.
(Ord k, Ord (PatchTarget p), Monoid p) =>
Map k (PatchTarget p)
-> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p
PM.patchThatChangesMap Map k v
Map k (PatchTarget (Proxy v))
oldByIndex Map k v
Map k (PatchTarget (Proxy v))
newByIndex
newtype NodeInfo k (v :: Type) = NodeInfo' { NodeInfo k v -> NodeInfo k (Proxy v)
unNodeInfo' :: PM.NodeInfo k (Proxy v) }
deriving instance (Show k, Show p) => Show (NodeInfo k p)
deriving instance (Read k, Read p) => Read (NodeInfo k p)
deriving instance (Eq k, Eq p) => Eq (NodeInfo k p)
deriving instance (Ord k, Ord p) => Ord (NodeInfo k p)
{-# COMPLETE NodeInfo #-}
pattern NodeInfo :: To k -> From k v -> NodeInfo k v
_nodeInfo_to :: NodeInfo k v -> To k
_nodeInfo_from :: NodeInfo k v -> From k v
pattern $bNodeInfo :: To k -> From k v -> NodeInfo k v
$mNodeInfo :: forall r k v.
NodeInfo k v -> (To k -> From k v -> r) -> (Void# -> r) -> r
NodeInfo { NodeInfo k v -> To k
_nodeInfo_to, NodeInfo k v -> From k v
_nodeInfo_from } = NodeInfo'
PM.NodeInfo
{ PM._nodeInfo_to = _nodeInfo_to
, PM._nodeInfo_from = Coerce _nodeInfo_from
}
_NodeInfo
:: Iso
(NodeInfo k0 v0)
(NodeInfo k1 v1)
(PM.NodeInfo k0 (Proxy v0))
(PM.NodeInfo k1 (Proxy v1))
_NodeInfo :: p (NodeInfo k0 (Proxy v0)) (f (NodeInfo k1 (Proxy v1)))
-> p (NodeInfo k0 v0) (f (NodeInfo k1 v1))
_NodeInfo = (NodeInfo k0 v0 -> NodeInfo k0 (Proxy v0))
-> (NodeInfo k1 (Proxy v1) -> NodeInfo k1 v1)
-> Iso
(NodeInfo k0 v0)
(NodeInfo k1 v1)
(NodeInfo k0 (Proxy v0))
(NodeInfo k1 (Proxy v1))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso NodeInfo k0 v0 -> NodeInfo k0 (Proxy v0)
forall k v. NodeInfo k v -> NodeInfo k (Proxy v)
unNodeInfo' NodeInfo k1 (Proxy v1) -> NodeInfo k1 v1
forall k v. NodeInfo k (Proxy v) -> NodeInfo k v
NodeInfo'
instance Functor (NodeInfo k) where
fmap :: (a -> b) -> NodeInfo k a -> NodeInfo k b
fmap a -> b
f = Identity (NodeInfo k b) -> NodeInfo k b
forall a. Identity a -> a
runIdentity (Identity (NodeInfo k b) -> NodeInfo k b)
-> (NodeInfo k a -> Identity (NodeInfo k b))
-> NodeInfo k a
-> NodeInfo k b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Identity b) -> NodeInfo k a -> Identity (NodeInfo k b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b) -> (a -> b) -> a -> Identity b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
instance Foldable (NodeInfo k) where
foldMap :: (a -> m) -> NodeInfo k a -> m
foldMap = (a -> m) -> NodeInfo k a -> m
forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault
instance Traversable (NodeInfo k) where
traverse :: (a -> f b) -> NodeInfo k a -> f (NodeInfo k b)
traverse = (k -> f k) -> (a -> f b) -> NodeInfo k a -> f (NodeInfo k b)
forall (f :: * -> *) k0 k1 v0 v1.
Applicative f =>
(k0 -> f k1)
-> (v0 -> f v1) -> NodeInfo k0 v0 -> f (NodeInfo k1 v1)
bitraverseNodeInfo k -> f k
forall (f :: * -> *) a. Applicative f => a -> f a
pure
bitraverseNodeInfo
:: Applicative f
=> (k0 -> f k1)
-> (v0 -> f v1)
-> NodeInfo k0 v0 -> f (NodeInfo k1 v1)
bitraverseNodeInfo :: (k0 -> f k1)
-> (v0 -> f v1) -> NodeInfo k0 v0 -> f (NodeInfo k1 v1)
bitraverseNodeInfo k0 -> f k1
fk v0 -> f v1
fv = (NodeInfo k1 (Proxy v1) -> NodeInfo k1 v1)
-> f (NodeInfo k1 (Proxy v1)) -> f (NodeInfo k1 v1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NodeInfo k1 (Proxy v1) -> NodeInfo k1 v1
forall k v. NodeInfo k (Proxy v) -> NodeInfo k v
NodeInfo'
(f (NodeInfo k1 (Proxy v1)) -> f (NodeInfo k1 v1))
-> (NodeInfo k0 v0 -> f (NodeInfo k1 (Proxy v1)))
-> NodeInfo k0 v0
-> f (NodeInfo k1 v1)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k0 -> f k1)
-> (Proxy v0 -> f (Proxy v1))
-> (PatchTarget (Proxy v0) -> f (PatchTarget (Proxy v1)))
-> NodeInfo k0 (Proxy v0)
-> f (NodeInfo k1 (Proxy v1))
forall (f :: * -> *) k0 k1 p0 p1.
Applicative f =>
(k0 -> f k1)
-> (p0 -> f p1)
-> (PatchTarget p0 -> f (PatchTarget p1))
-> NodeInfo k0 p0
-> f (NodeInfo k1 p1)
PM.bitraverseNodeInfo k0 -> f k1
fk (\ ~Proxy v0
Proxy -> Proxy v1 -> f (Proxy v1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy v1
forall k (t :: k). Proxy t
Proxy) v0 -> f v1
PatchTarget (Proxy v0) -> f (PatchTarget (Proxy v1))
fv
(NodeInfo k0 (Proxy v0) -> f (NodeInfo k1 (Proxy v1)))
-> (NodeInfo k0 v0 -> NodeInfo k0 (Proxy v0))
-> NodeInfo k0 v0
-> f (NodeInfo k1 (Proxy v1))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeInfo k0 v0 -> NodeInfo k0 (Proxy v0)
coerce
nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v
nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v
nodeInfoMapFrom From k v -> From k v
f = (NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> NodeInfo k v -> NodeInfo k v
coerce ((NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> NodeInfo k v -> NodeInfo k v)
-> (NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> NodeInfo k v
-> NodeInfo k v
forall a b. (a -> b) -> a -> b
$ (From k (Proxy v) -> From k (Proxy v))
-> NodeInfo k (Proxy v) -> NodeInfo k (Proxy v)
forall k v. (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v
PM.nodeInfoMapFrom (From k v -> From k (Proxy v)
forall k v. From k v -> From k (Proxy v)
unFrom' (From k v -> From k (Proxy v))
-> (From k (Proxy v) -> From k v)
-> From k (Proxy v)
-> From k (Proxy v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. From k v -> From k v
f (From k v -> From k v)
-> (From k (Proxy v) -> From k v) -> From k (Proxy v) -> From k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. From k (Proxy v) -> From k v
forall k v. From k (Proxy v) -> From k v
From')
nodeInfoMapMFrom
:: Functor f
=> (From k v -> f (From k v))
-> NodeInfo k v -> f (NodeInfo k v)
nodeInfoMapMFrom :: (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v)
nodeInfoMapMFrom From k v -> f (From k v)
f = (NodeInfo k (Proxy v) -> NodeInfo k v)
-> f (NodeInfo k (Proxy v)) -> f (NodeInfo k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NodeInfo k (Proxy v) -> NodeInfo k v
forall k v. NodeInfo k (Proxy v) -> NodeInfo k v
NodeInfo'
(f (NodeInfo k (Proxy v)) -> f (NodeInfo k v))
-> (NodeInfo k v -> f (NodeInfo k (Proxy v)))
-> NodeInfo k v
-> f (NodeInfo k v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (From k (Proxy v) -> f (From k (Proxy v)))
-> NodeInfo k (Proxy v) -> f (NodeInfo k (Proxy v))
forall (f :: * -> *) k v.
Functor f =>
(From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v)
PM.nodeInfoMapMFrom ((From k v -> From k (Proxy v))
-> f (From k v) -> f (From k (Proxy v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap From k v -> From k (Proxy v)
forall k v. From k v -> From k (Proxy v)
unFrom' (f (From k v) -> f (From k (Proxy v)))
-> (From k (Proxy v) -> f (From k v))
-> From k (Proxy v)
-> f (From k (Proxy v))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. From k v -> f (From k v)
f (From k v -> f (From k v))
-> (From k (Proxy v) -> From k v)
-> From k (Proxy v)
-> f (From k v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. From k (Proxy v) -> From k v
forall k v. From k (Proxy v) -> From k v
From')
(NodeInfo k (Proxy v) -> f (NodeInfo k (Proxy v)))
-> (NodeInfo k v -> NodeInfo k (Proxy v))
-> NodeInfo k v
-> f (NodeInfo k (Proxy v))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeInfo k v -> NodeInfo k (Proxy v)
coerce
nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v
nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v
nodeInfoSetTo = (NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> NodeInfo k v -> NodeInfo k v
coerce ((NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> NodeInfo k v -> NodeInfo k v)
-> (To k -> NodeInfo k (Proxy v) -> NodeInfo k (Proxy v))
-> To k
-> NodeInfo k v
-> NodeInfo k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. To k -> NodeInfo k (Proxy v) -> NodeInfo k (Proxy v)
forall k v. To k -> NodeInfo k v -> NodeInfo k v
PM.nodeInfoSetTo
newtype From k (v :: Type) = From' { From k v -> From k (Proxy v)
unFrom' :: PM.From k (Proxy v) }
{-# COMPLETE From_Insert, From_Delete, From_Move #-}
pattern From_Insert :: v -> From k v
pattern $bFrom_Insert :: v -> From k v
$mFrom_Insert :: forall r v k. From k v -> (v -> r) -> (Void# -> r) -> r
From_Insert v = From' (PM.From_Insert v)
pattern From_Delete :: From k v
pattern $bFrom_Delete :: From k v
$mFrom_Delete :: forall r k v. From k v -> (Void# -> r) -> (Void# -> r) -> r
From_Delete = From' PM.From_Delete
pattern From_Move :: k -> From k v
pattern $bFrom_Move :: k -> From k v
$mFrom_Move :: forall r k v. From k v -> (k -> r) -> (Void# -> r) -> r
From_Move k = From' (PM.From_Move k Proxy)
bitraverseFrom
:: Applicative f
=> (k0 -> f k1)
-> (v0 -> f v1)
-> From k0 v0 -> f (From k1 v1)
bitraverseFrom :: (k0 -> f k1) -> (v0 -> f v1) -> From k0 v0 -> f (From k1 v1)
bitraverseFrom k0 -> f k1
fk v0 -> f v1
fv = (From k1 (Proxy v1) -> From k1 v1)
-> f (From k1 (Proxy v1)) -> f (From k1 v1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap From k1 (Proxy v1) -> From k1 v1
forall k v. From k (Proxy v) -> From k v
From'
(f (From k1 (Proxy v1)) -> f (From k1 v1))
-> (From k0 v0 -> f (From k1 (Proxy v1)))
-> From k0 v0
-> f (From k1 v1)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k0 -> f k1)
-> (Proxy v0 -> f (Proxy v1))
-> (PatchTarget (Proxy v0) -> f (PatchTarget (Proxy v1)))
-> From k0 (Proxy v0)
-> f (From k1 (Proxy v1))
forall (f :: * -> *) k0 k1 p0 p1.
Applicative f =>
(k0 -> f k1)
-> (p0 -> f p1)
-> (PatchTarget p0 -> f (PatchTarget p1))
-> From k0 p0
-> f (From k1 p1)
PM.bitraverseFrom k0 -> f k1
fk (\ ~Proxy v0
Proxy -> Proxy v1 -> f (Proxy v1)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy v1
forall k (t :: k). Proxy t
Proxy) v0 -> f v1
PatchTarget (Proxy v0) -> f (PatchTarget (Proxy v1))
fv
(From k0 (Proxy v0) -> f (From k1 (Proxy v1)))
-> (From k0 v0 -> From k0 (Proxy v0))
-> From k0 v0
-> f (From k1 (Proxy v1))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. From k0 v0 -> From k0 (Proxy v0)
coerce
makeWrapped ''PatchMapWithMove
makeWrapped ''NodeInfo
makeWrapped ''From