Skip to content

Commit 2c089e3

Browse files
committed
Change functions' categories; add test for example
1 parent 8f1c906 commit 2c089e3

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

Sources/Algorithms/Documentation.docc/Filtering.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ let withNoNils = array.compacted()
2121
// Array(withNoNils) == [10, 30, 2, 3, 5]
2222
```
2323

24+
The `withoutSortedDuplicates()` methods remove consecutive elements of the same equivalence class from an already sorted sequence, turning a possibly non-decreasing sequence to a strictly-increasing one. The sorting predicate can be supplied.
25+
26+
```swift
27+
let numbers = [0, 1, 2, 2, 2, 3, 5, 6, 6, 9, 10, 10]
28+
let deduplicated = numbers.withoutSortedDuplicates()
29+
// Array(deduplicated) == [0, 1, 2, 3, 5, 6, 9, 10]
30+
```
31+
2432
## Topics
2533

2634
### Uniquing Elements
@@ -34,6 +42,13 @@ let withNoNils = array.compacted()
3442
- ``Swift/Collection/compacted()``
3543
- ``Swift/Sequence/compacted()``
3644

45+
### Removing Duplicates from a Sorted Sequence
46+
47+
- ``Swift/Sequence/withoutSortedDuplicates(by:)``
48+
- ``Swift/Sequence/withoutSortedDuplicates()``
49+
- ``Swift/LazySequenceProtocol/withoutSortedDuplicates(by:)``
50+
- ``Swift/LazySequenceProtocol/withoutSortedDuplicates()``
51+
3752
### Supporting Types
3853

3954
- ``UniquedSequence``

Sources/Algorithms/Documentation.docc/Keying.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ Convert a sequence to a dictionary, providing keys to individual elements or to
1212
### Grouping Elements by Key
1313

1414
- ``Swift/Sequence/grouped(by:)``
15+
16+
### Counting each Element in a Sorted Sequence
17+
18+
- ``Swift/Sequence/countSortedDuplicates(by:)``
19+
- ``Swift/Sequence/countSortedDuplicates()``
20+
- ``Swift/LazySequenceProtocol/countSortedDuplicates(by:)``
21+
- ``Swift/LazySequenceProtocol/countSortedDuplicates()``
22+
23+
### Supporting Types
24+
25+
- ``LazyCountDuplicatesSequence``
26+
- ``CountDuplicatesIterator``

Sources/Algorithms/Documentation.docc/Selecting.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,8 @@ or iterate of elements with their indices.
1818

1919
- ``Swift/Collection/indexed()``
2020

21-
### Counting each Element in a Sorted Sequence
22-
23-
- ``Swift/Sequence/countSortedDuplicates(by:)``
24-
- ``Swift/Sequence/countSortedDuplicates()``
25-
- ``Swift/LazySequenceProtocol/countSortedDuplicates(by:)``
26-
- ``Swift/LazySequenceProtocol/countSortedDuplicates()``
27-
28-
### Removing Duplicates from a Sorted Sequence
29-
30-
- ``Swift/Sequence/withoutSortedDuplicates(by:)``
31-
- ``Swift/Sequence/withoutSortedDuplicates()``
32-
- ``Swift/LazySequenceProtocol/withoutSortedDuplicates(by:)``
33-
- ``Swift/LazySequenceProtocol/withoutSortedDuplicates()``
34-
3521
### Supporting Types
3622

3723
- ``IndexedCollection``
3824
- ``StridingSequence``
3925
- ``StridingCollection``
40-
- ``LazyCountDuplicatesSequence``
41-
- ``CountDuplicatesIterator``

Tests/SwiftAlgorithmsTests/SortedDuplicatesTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,13 @@ final class SortedDuplicatesTests: XCTestCase {
7979
expectEqualSequences(lazySampleCounts.map(\.count), expected.map(\.1))
8080
expectEqualSequences(sample.lazy.deduplicateSorted(), "Xacdfxz")
8181
}
82+
83+
/// Test the example code from the Overview.
84+
func testOverviewExample() {
85+
let numbers = [0, 1, 2, 2, 2, 3, 5, 6, 6, 9, 10, 10]
86+
let deduplicated = numbers.withoutSortedDuplicates()
87+
// Array(deduplicated) == [0, 1, 2, 3, 5, 6, 9, 10]
88+
89+
expectEqualSequences(deduplicated, [0, 1, 2, 3, 5, 6, 9, 10])
90+
}
8291
}

0 commit comments

Comments
 (0)