From 8cd74f6ea2a274eb7045771fd4f6c15ef1e0c785 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 5 May 2017 15:26:26 -0400 Subject: [PATCH] afterOrBefore always returns a value. --- src/Patch.hs | 10 +++++----- src/Renderer/TOC.hs | 8 ++------ 2 files changed, 7 insertions(+), 11 deletions(-) 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