1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 18:36:27 +03:00

Simplify tableOfContentsBy.

This commit is contained in:
Rob Rix 2017-05-10 10:00:20 -04:00
parent 0534c3303d
commit 86f852c8f0

View File

@ -59,12 +59,10 @@ data Entry a
deriving (Eq, Show)
tableOfContentsBy :: Traversable f => (forall b. TermF f (Record fields) b -> Bool) -> Diff f (Record fields) -> [Entry (Record fields)]
tableOfContentsBy isRelevant = fromMaybe [] . iter alg . fmap (Just . fmap (Changed . Right) . crosswalk (cata termAlgebra))
where alg r | isRelevant (first Both.snd r)
, annotation <- Both.snd (headF r) = Just (maybe [Unchanged annotation] (wrapList annotation) (fold r))
| otherwise = fold r
wrapList a es | null es = [Changed (Left a)]
| otherwise = es
tableOfContentsBy isRelevant = fromMaybe [] . iter diffAlgebra . fmap (Just . fmap (Changed . Right) . crosswalk (cata termAlgebra))
where diffAlgebra r | isRelevant (first Both.snd r)
, annotation <- Both.snd (headF r) = Just (maybe [Unchanged annotation] (maybe [Changed (Left annotation)] (uncurry (:)) . uncons) (fold r))
| otherwise = fold r
termAlgebra r | isRelevant r = [headF r]
| otherwise = fold r