@@ -22,16 +22,6 @@ import Data.Patch.Class
22-- and @Nothing@ means delete.
22-- and @Nothing@ means delete.
23newtype PatchIntMap a = PatchIntMap (IntMap (Maybe a)) deriving (Functor, Foldable, Traversable, Monoid)
23newtype PatchIntMap a = PatchIntMap (IntMap (Maybe a)) deriving (Functor, Foldable, Traversable, Monoid)
25−-- | Apply the insertions or deletions to a given 'IntMap'.
26−instance Patch (PatchIntMap a) where
27− type PatchTarget (PatchIntMap a) = IntMap a
28− apply (PatchIntMap p) v = if IntMap.null p then Nothing else Just $
29− let removes = IntMap.filter isNothing p
30− adds = IntMap.mapMaybe id p
31− in IntMap.union adds $ v `IntMap.difference` removes
33−makeWrapped ''PatchIntMap
35-- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@.
25-- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@.
36-- If the same key is modified by both patches, the one on the left will take
26-- If the same key is modified by both patches, the one on the left will take
37-- precedence.
27-- precedence.
@@ -40,6 +30,16 @@ instance Semigroup (PatchIntMap v) where
40 -- PatchMap is idempotent, so stimes n is id for every n
30 -- PatchMap is idempotent, so stimes n is id for every n
41 stimes = stimesIdempotentMonoid
31 stimes = stimesIdempotentMonoid
33+makeWrapped ''PatchIntMap
35+-- | Apply the insertions or deletions to a given 'IntMap'.
36+instance Patch (PatchIntMap a) where
37+ type PatchTarget (PatchIntMap a) = IntMap a
38+ apply (PatchIntMap p) v = if IntMap.null p then Nothing else Just $
39+ let removes = IntMap.filter isNothing p
40+ adds = IntMap.mapMaybe id p
41+ in IntMap.union adds $ v `IntMap.difference` removes
43instance FunctorWithIndex Int PatchIntMap
43instance FunctorWithIndex Int PatchIntMap
44instance FoldableWithIndex Int PatchIntMap
44instance FoldableWithIndex Int PatchIntMap
45instance TraversableWithIndex Int PatchIntMap where
45instance TraversableWithIndex Int PatchIntMap where