1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +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) deriving (Eq, Show)
tableOfContentsBy :: Traversable f => (forall b. TermF f (Record fields) b -> Bool) -> Diff f (Record fields) -> [Entry (Record fields)] 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)) tableOfContentsBy isRelevant = fromMaybe [] . iter diffAlgebra . fmap (Just . fmap (Changed . Right) . crosswalk (cata termAlgebra))
where alg r | isRelevant (first Both.snd r) where diffAlgebra r | isRelevant (first Both.snd r)
, annotation <- Both.snd (headF r) = Just (maybe [Unchanged annotation] (wrapList annotation) (fold r)) , annotation <- Both.snd (headF r) = Just (maybe [Unchanged annotation] (maybe [Changed (Left annotation)] (uncurry (:)) . uncons) (fold r))
| otherwise = fold r | otherwise = fold r
wrapList a es | null es = [Changed (Left a)]
| otherwise = es
termAlgebra r | isRelevant r = [headF r] termAlgebra r | isRelevant r = [headF r]
| otherwise = fold r | otherwise = fold r