@@ -22,16 +22,6 @@ import Data.Patch.Class
22
22
-- and @Nothing@ means delete.
23
23
newtype PatchIntMap a = PatchIntMap (IntMap (Maybe a )) deriving (Functor , Foldable , Traversable , Monoid )
24
24
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
-
35
25
-- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@.
36
26
-- If the same key is modified by both patches, the one on the left will take
37
27
-- precedence.
@@ -40,6 +30,16 @@ instance Semigroup (PatchIntMap v) where
40
30
-- PatchMap is idempotent, so stimes n is id for every n
41
31
stimes = stimesIdempotentMonoid
42
32
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
+
43
43
instance FunctorWithIndex Int PatchIntMap
44
44
instance FoldableWithIndex Int PatchIntMap
45
45
instance TraversableWithIndex Int PatchIntMap where
0 commit comments