Skip to content

Commit 9da0ce0

Browse files
committed
Simplify itraverse{d} to not care about exact shape of newtypes
1 parent c6216d3 commit 9da0ce0

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Data/Patch/IntMap.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ instance Patch (PatchIntMap a) where
4545
instance FunctorWithIndex Int PatchIntMap
4646
instance FoldableWithIndex Int PatchIntMap
4747
instance TraversableWithIndex Int PatchIntMap where
48-
itraversed = _Wrapped . itraversed . traversed
48+
itraverse = itraversed . Indexed
49+
itraversed = _Wrapped .> itraversed <. traversed
4950

5051
-- | Map a function @Int -> a -> b@ over all @a@s in the given @'PatchIntMap' a@
5152
-- (that is, all inserts/updates), producing a @PatchIntMap b@.

src/Data/Patch/Map.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ instance Ord k => Patch (PatchMap k v) where
5454
instance FunctorWithIndex k (PatchMap k)
5555
instance FoldableWithIndex k (PatchMap k)
5656
instance TraversableWithIndex k (PatchMap k) where
57-
itraverse f (PatchMap x) = PatchMap <$> itraverse (traverse . f) x
57+
itraverse = itraversed . Indexed
58+
itraversed = _Wrapped .> itraversed <. traversed
5859

5960
-- | The empty 'PatchMap' contains no insertions or deletions
6061
instance Ord k => Monoid (PatchMap k v) where

src/Data/Patch/MapWithMove.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ makeWrapped ''PatchMapWithMove
6868
instance FunctorWithIndex k (PatchMapWithMove k)
6969
instance FoldableWithIndex k (PatchMapWithMove k)
7070
instance TraversableWithIndex k (PatchMapWithMove k) where
71-
itraverse f (PatchMapWithMove x) = PatchMapWithMove <$> itraverse (traverse . f) x
71+
itraverse = itraversed . Indexed
72+
itraversed = _Wrapped .> itraversed <. traversed
7273

7374
-- | Create a 'PatchMapWithMove', validating it
7475
patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v)

0 commit comments

Comments
 (0)