diff --git a/src/Patch.hs b/src/Patch.hs index 8f42e1ee6..768cba42c 100644 --- a/src/Patch.hs +++ b/src/Patch.hs @@ -51,11 +51,11 @@ after = maybeSnd . unPatch before :: Patch a -> Maybe a before = maybeFst . unPatch -afterOrBefore :: Patch a -> Maybe a -afterOrBefore patch = case (before patch, after patch) of - (_, Just after) -> Just after - (Just before, _) -> Just before - (_, _) -> Nothing +afterOrBefore :: Patch a -> a +afterOrBefore patch = case patch of + Insert after -> after + Delete before -> before + Replace _ after -> after -- | Return both sides of a patch. unPatch :: Patch a -> These a a diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index a4583f1e9..04df803a5 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -103,9 +103,7 @@ diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >> -- Mark which leaves are summarizable. toTOCSummaries :: Patch DiffInfo -> [TOCSummary DiffInfo] -toTOCSummaries patch = case afterOrBefore patch of - Just diffInfo -> toTOCSummaries' patch diffInfo - Nothing -> panic "No diff" +toTOCSummaries patch = toTOCSummaries' patch (afterOrBefore patch) where toTOCSummaries' patch' diffInfo = case diffInfo of ErrorInfo{..} -> pure $ TOCSummary patch' NotSummarizable @@ -147,9 +145,7 @@ summarizable term = go (unwrap term) term _ -> NotSummarizableTerm toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary] -toJSONSummaries TOCSummary{..} = case afterOrBefore summaryPatch of - Just diffInfo -> toJSONSummaries' diffInfo - Nothing -> panic "No diff" +toJSONSummaries TOCSummary{..} = toJSONSummaries' (afterOrBefore summaryPatch) where toJSONSummaries' diffInfo = case diffInfo of ErrorInfo{..} -> pure $ ErrorSummary termName infoSpan