diff --git a/src/Rendering/TOC.hs b/src/Rendering/TOC.hs index 6b4f1b758..16a53aa3d 100644 --- a/src/Rendering/TOC.hs +++ b/src/Rendering/TOC.hs @@ -98,18 +98,19 @@ newtype DedupeKey = DedupeKey (T.Text, T.Text) deriving (Eq, Ord) -- identifiers) are in the list. -- Action: Combine them into a single Replaced entry. dedupe :: [(Entry, Declaration)] -> [(Entry, Declaration)] -dedupe = map snd . sortOn fst . Map.elems . snd . foldl' go (0, Map.empty) +dedupe = map snd . sortOn fst . Map.elems . snd . foldl' (uncurry . go) (0, Map.empty) where go :: (Int, Map.Map DedupeKey (Int, (Entry, Declaration))) - -> (Entry, Declaration) + -> Entry + -> Declaration -> (Int, Map.Map DedupeKey (Int, (Entry, Declaration))) - go (index, m) x - | Just (_, (_, similarDecl)) <- Map.lookup (dedupeKey (snd x)) m - = (succ index,) $ if similarDecl == snd x then + go (index, m) entry decl + | Just (_, (_, similarDecl)) <- Map.lookup (dedupeKey decl) m + = (succ index,) $ if similarDecl == decl then m else Map.insert (dedupeKey similarDecl) (index, (Replaced, similarDecl)) m - | otherwise = (succ index, Map.insert (dedupeKey (snd x)) (index, x) m) + | otherwise = (succ index, Map.insert (dedupeKey decl) (index, (entry, decl)) m) dedupeKey decl = DedupeKey (toCategoryName decl, T.toLower (declarationIdentifier decl))