1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Define a Foldable instance for Diff.

This commit is contained in:
Rob Rix 2017-09-09 13:40:07 +01:00
parent a9ac82819c
commit ff1cc394c4

View File

@ -137,6 +137,11 @@ instance Functor f => Functor (Diff f) where
where go (Diff (Copy as r)) = Diff (Copy (f <$> as) (fmap go r))
go (Diff (Patch p)) = Diff (Patch (fmap f <$> p))
instance Foldable f => Foldable (Diff f) where
foldMap f = go
where go (Diff (Copy as r)) = foldMap f as `mappend` foldMap go r
go (Diff (Patch p)) = foldMap (foldMap f) p
instance Foldable f => Bifoldable (DiffF f) where
bifoldMap f g (Copy as r) = foldMap f as `mappend` foldMap g r