1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Define a convenience wrapper for foldDiffWith when the result is a Monoid.

This commit is contained in:
Rob Rix 2017-05-08 12:42:36 -04:00
parent a4cb5c5a30
commit 6f56bc980a

View File

@ -50,6 +50,9 @@ mapAnnotations f = iter (wrap . first (fmap f)) . fmap (pure . fmap (fmap f))
foldDiffWith :: Functor f => (TermF f (These a a) b -> b) -> (b -> b -> b) -> Diff f a -> b
foldDiffWith algebra merge = iter (algebra . first (runBothWith These)) . fmap (mergeTheseWith (cata algebra . fmap This) (cata algebra . fmap That) merge . unPatch)
foldDiff :: (Monoid b, Functor f) => (TermF f (These a a) b -> b) -> Diff f a -> b
foldDiff algebra = foldDiffWith algebra mappend
instance (NFData (f (Diff f a)), NFData (Cofree f a), NFData a, Functor f) => NFData (Diff f a) where
rnf fa = case runFree fa of