@@ -22,16 +22,6 @@ import Data.Patch.Class
2222-- and @Nothing@ means delete.
2323newtype PatchIntMap a = PatchIntMap (IntMap (Maybe a)) deriving (Functor, Foldable, Traversable, Monoid)
2424
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
32−
33−makeWrapped ''PatchIntMap
34−
3525-- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@.
3626-- If the same key is modified by both patches, the one on the left will take
3727-- precedence.
@@ -40,6 +30,16 @@ instance Semigroup (PatchIntMap v) where
4030 -- PatchMap is idempotent, so stimes n is id for every n
4131 stimes = stimesIdempotentMonoid
4232
33+makeWrapped ''PatchIntMap
34+
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
42+
4343instance FunctorWithIndex Int PatchIntMap
4444instance FoldableWithIndex Int PatchIntMap
4545instance TraversableWithIndex Int PatchIntMap where