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

Add a merging function to foldDiff.

This commit is contained in:
Rob Rix 2017-05-08 12:41:26 -04:00
parent 9fee3b2bc5
commit a4cb5c5a30

View File

@ -47,8 +47,8 @@ mapAnnotations :: (Functor f, Functor g)
mapAnnotations f = iter (wrap . first (fmap f)) . fmap (pure . fmap (fmap f))
foldDiff :: Functor f => (TermF f (These a a) b -> b) -> Diff f a -> b
foldDiff algebra = iter (algebra . first (runBothWith These)) . fmap (mergeTheseWith (cata algebra . fmap This) (cata algebra . fmap That) const . unPatch)
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)
instance (NFData (f (Diff f a)), NFData (Cofree f a), NFData a, Functor f) => NFData (Diff f a) where