Skip to content

Commit e5661a7

Browse files
authored
Add flattenSCC1 :: SCC a -> NonEmpty a (#987)
This gives a more precise type compared to the existing `flattenSCC :: SCC a -> [a]`.
1 parent d66f3b3 commit e5661a7

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

containers/changelog.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
`Data.IntSet.splitMember` are now strict in the key. Previously, the key was
1010
ignored for an empty map or set. (Soumik Sarkar)
1111

12+
## Unreleased with `@since` annotation for 0.7.1:
13+
14+
### Additions
15+
16+
* Add `Data.Graph.flattenSCC1`. (Andreas Abel)
17+
1218
## 0.7
1319

1420
### Breaking changes
@@ -327,13 +333,13 @@ modules.
327333

328334
* Rewrite the `IsString` instance head for sequences, improving compatibility
329335
with the list instance and also improving type inference. We used to have
330-
336+
331337
```haskell
332338
instance IsString (Seq Char)
333339
```
334-
340+
335341
Now we commit more eagerly with
336-
342+
337343
```haskell
338344
instance a ~ Char => IsString (Seq a)
339345
```
@@ -407,7 +413,7 @@ modules.
407413
* Fix completely incorrect implementations of `Data.IntMap.restrictKeys` and
408414
`Data.IntMap.withoutKeys`. Make the tests for these actually run. (Thanks
409415
to Tom Smalley for reporting this.)
410-
416+
411417
* Fix a minor bug in the `Show1` instance of `Data.Tree`. This produced valid
412418
output, but with fewer parentheses than `Show`. (Thanks, Ryan Scott.)
413419

@@ -462,7 +468,7 @@ performance improvements overall.
462468
before 7.0.
463469

464470
* Integrate benchmarks with Cabal. (Thanks, Gabriel Gonzalez!)
465-
471+
466472
* Make Cabal report required extensions properly, and stop using
467473
default extensions. Note that we do *not* report extensions conditionally enabled
468474
based on GHC version, as doing so would lead to a maintenance nightmare
@@ -512,7 +518,7 @@ performance improvements overall.
512518
it returned a lazy pair.
513519

514520
* Fix completely erroneous definition of `length` for `Data.Sequence.ViewR`.
515-
521+
516522
* Make `Data.Map.Strict.traverseWithKey` force result values before
517523
installing them in the new map.
518524

containers/src/Data/Graph.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module Data.Graph (
8989

9090
-- ** Conversion
9191
, flattenSCC
92+
, flattenSCC1
9293
, flattenSCCs
9394

9495
-- * Trees
@@ -246,9 +247,20 @@ flattenSCCs :: [SCC a] -> [a]
246247
flattenSCCs = concatMap flattenSCC
247248

248249
-- | The vertices of a strongly connected component.
250+
--
251+
-- @flattenSCC = 'Data.List.NonEmpty.toList' . 'flattenSCC1'@.
252+
--
253+
-- This function is retained for backward compatibility,
254+
-- 'flattenSCC1' has the more precise type.
249255
flattenSCC :: SCC vertex -> [vertex]
250-
flattenSCC (AcyclicSCC v) = [v]
251-
flattenSCC (NECyclicSCC vs) = NE.toList vs
256+
flattenSCC = NE.toList . flattenSCC1
257+
258+
-- | The vertices of a strongly connected component.
259+
--
260+
-- @since 0.7.1
261+
flattenSCC1 :: SCC vertex -> NonEmpty vertex
262+
flattenSCC1 (AcyclicSCC v) = v :| []
263+
flattenSCC1 (NECyclicSCC vs) = vs
252264

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

0 commit comments

Comments
 (0)