Skip to content

Commit

Permalink
Add flattenSCC1 :: SCC a -> NonEmpty a
Browse files Browse the repository at this point in the history
This gives a more precise type to the existing `flattenSCC :: SCC a -> [a]`.
Closes #985.
  • Loading branch information
andreasabel committed Feb 2, 2024
1 parent 3c13e0b commit fd3312c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions containers/src/Data/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ flattenSCCs :: [SCC a] -> [a]
flattenSCCs = concatMap flattenSCC

-- | The vertices of a strongly connected component.
--
-- @flattenSCC = 'Data.List.NonEmpty.toList' . 'flattenSCC1'@.
--
-- This function is retained for backward compatibility,
-- 'flattenSCC1' has the more precise type.
flattenSCC :: SCC vertex -> [vertex]
flattenSCC (AcyclicSCC v) = [v]
flattenSCC (NECyclicSCC vs) = NE.toList vs
flattenSCC = NE.toList . flattenSCC1

-- | The vertices of a strongly connected component.
flattenSCC1 :: SCC vertex -> NonEmpty vertex
flattenSCC1 (AcyclicSCC v) = v :| []
flattenSCC1 (NECyclicSCC vs) = vs

-- | \(O((V+E) \log V)\). The strongly connected components of a directed graph,
-- reverse topologically sorted.
Expand Down

0 comments on commit fd3312c

Please sign in to comment.