From 6f56bc980a8375bc13a825120b84ce2e97993697 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 8 May 2017 12:42:36 -0400 Subject: [PATCH] Define a convenience wrapper for foldDiffWith when the result is a Monoid. --- src/Diff.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Diff.hs b/src/Diff.hs index 34fd2ba60..e2d7510b0 100644 --- a/src/Diff.hs +++ b/src/Diff.hs @@ -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