Skip to content

Commit 3ea695b

Browse files
committed
Rename combinations(ofCounts:) to combinations(ofCount:)
1 parent f645793 commit 3ea695b

File tree

4 files changed

+34
-40
lines changed

4 files changed

+34
-40
lines changed

Guides/Combinations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ for combo in numbers2.combinations(ofCount: 2) {
3636
// [10, 10]
3737
```
3838

39-
The `combinations(ofCounts:)` method returns a sequence of all the different
40-
combinations of the given sizes of a collection’s elements in increasing order
41-
of size.
39+
Given a range, the `combinations(ofCount:)` method returns a sequence of all
40+
the different combinations of the given sizes of a collection’s elements in
41+
increasing order of size.
4242

4343
```swift
4444
let numbers = [10, 20, 30, 40]
45-
for combo in numbers(ofCounts: 2...3) {
45+
for combo in numbers(ofCount: 2...3) {
4646
print(combo)
4747
}
4848
// [10, 20]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Read more about the package, and the intent behind it, in the [announcement on s
88

99
#### Combinations / permutations
1010

11-
- [`combinations(ofCount:)`, `combinations(ofCounts:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Combinations.md): Combinations of particular sizes of the elements in a collection.
11+
- [`combinations(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Combinations.md): Combinations of particular sizes of the elements in a collection.
1212
- [`permutations(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Permutations.md): Permutations of a particular size of the elements in a collection, or of the full collection.
1313

1414
#### Mutating algorithms

Sources/Algorithms/Combinations.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extension Combinations: Equatable where Base: Equatable {}
177177
extension Combinations: Hashable where Base: Hashable {}
178178

179179
//===----------------------------------------------------------------------===//
180-
// combinations(ofCounts:)
180+
// combinations(ofCount:)
181181
//===----------------------------------------------------------------------===//
182182

183183
extension Collection {
@@ -188,7 +188,7 @@ extension Collection {
188188
/// four colors:
189189
///
190190
/// let colors = ["fuchsia", "cyan", "mauve", "magenta"]
191-
/// for combo in colors.combinations(ofCounts: 1...2) {
191+
/// for combo in colors.combinations(ofCount: 1...2) {
192192
/// print(combo.joined(separator: ", "))
193193
/// }
194194
/// // fuchsia
@@ -242,17 +242,11 @@ extension Collection {
242242
/// - Complexity: O(1)
243243
@inlinable
244244
public func combinations<R: RangeExpression>(
245-
ofCounts kRange: R
245+
ofCount kRange: R
246246
) -> Combinations<Self> where R.Bound == Int {
247247
return Combinations(self, kRange: kRange)
248248
}
249-
}
250-
251-
//===----------------------------------------------------------------------===//
252-
// combinations(ofCount:)
253-
//===----------------------------------------------------------------------===//
254-
255-
extension Collection {
249+
256250
/// Returns a collection of combinations of this collection's elements, with
257251
/// each combination having the specified number of elements.
258252
///

Tests/SwiftAlgorithmsTests/CombinationsTests.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,40 @@ final class CombinationsTests: XCTestCase {
3131
let c4 = c.combinations(ofCount: 4).count
3232
XCTAssertEqual(c4, 1)
3333

34-
let c5 = c.combinations(ofCounts: 0...0).count
34+
let c5 = c.combinations(ofCount: 0...0).count
3535
XCTAssertEqual(c5, 1)
3636

37-
let c6 = c.combinations(ofCounts: 1...1).count
37+
let c6 = c.combinations(ofCount: 1...1).count
3838
XCTAssertEqual(c6, 4)
3939

40-
let c7 = c.combinations(ofCounts: 1...2).count
40+
let c7 = c.combinations(ofCount: 1...2).count
4141
XCTAssertEqual(c7, 10)
4242

43-
let c8 = c.combinations(ofCounts: 1...3).count
43+
let c8 = c.combinations(ofCount: 1...3).count
4444
XCTAssertEqual(c8, 14)
4545

46-
let c9 = c.combinations(ofCounts: 2...4).count
46+
let c9 = c.combinations(ofCount: 2...4).count
4747
XCTAssertEqual(c9, 11)
4848

4949
// `k` greater than element count results in same number of combinations
50-
let c10 = c.combinations(ofCounts: 3...10).count
50+
let c10 = c.combinations(ofCount: 3...10).count
5151
XCTAssertEqual(c10, 5)
5252

5353
// `k` greater than element count results in same number of combinations
54-
let c11 = c.combinations(ofCounts: 4...10).count
54+
let c11 = c.combinations(ofCount: 4...10).count
5555
XCTAssertEqual(c11, 1)
5656

5757
// `k` entirely greater than element count results in no combinations
58-
let c12 = c.combinations(ofCounts: 5...10).count
58+
let c12 = c.combinations(ofCount: 5...10).count
5959
XCTAssertEqual(c12, 0)
6060

61-
let c13 = c.combinations(ofCounts: 0...).count
61+
let c13 = c.combinations(ofCount: 0...).count
6262
XCTAssertEqual(c13, 16)
6363

64-
let c14 = c.combinations(ofCounts: ...3).count
64+
let c14 = c.combinations(ofCount: ...3).count
6565
XCTAssertEqual(c14, 15)
6666

67-
let c15 = c.combinations(ofCounts: 0...).count
67+
let c15 = c.combinations(ofCount: 0...).count
6868
XCTAssertEqual(c15, 16)
6969
}
7070

@@ -83,44 +83,44 @@ final class CombinationsTests: XCTestCase {
8383
let c4 = c.combinations(ofCount: 4)
8484
XCTAssertEqual(["ABCD"], c4.map { String($0) })
8585

86-
let c5 = c.combinations(ofCounts: 2...4)
86+
let c5 = c.combinations(ofCount: 2...4)
8787
XCTAssertEqual(["AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD", "ABCD"], c5.map { String($0) })
8888

89-
let c6 = c.combinations(ofCounts: 0...4)
89+
let c6 = c.combinations(ofCount: 0...4)
9090
XCTAssertEqual(["", "A", "B", "C", "D", "AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD", "ABCD"], c6.map { String($0) })
9191

92-
let c7 = c.combinations(ofCounts: 0...)
92+
let c7 = c.combinations(ofCount: 0...)
9393
XCTAssertEqual(["", "A", "B", "C", "D", "AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD", "ABCD"], c7.map { String($0) })
9494

95-
let c8 = c.combinations(ofCounts: ...4)
95+
let c8 = c.combinations(ofCount: ...4)
9696
XCTAssertEqual(["", "A", "B", "C", "D", "AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD", "ABCD"], c8.map { String($0) })
9797

98-
let c9 = c.combinations(ofCounts: ...3)
98+
let c9 = c.combinations(ofCount: ...3)
9999
XCTAssertEqual(["", "A", "B", "C", "D", "AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD"], c9.map { String($0) })
100100

101-
let c10 = c.combinations(ofCounts: 1...)
101+
let c10 = c.combinations(ofCount: 1...)
102102
XCTAssertEqual(["A", "B", "C", "D", "AB", "AC", "AD", "BC", "BD", "CD", "ABC", "ABD", "ACD", "BCD", "ABCD"], c10.map { String($0) })
103103
}
104104

105105
func testEmpty() {
106106
// `k == 0` results in one zero-length combination
107107
XCTAssertEqualSequences([[]], "".combinations(ofCount: 0))
108-
XCTAssertEqualSequences([[]], "".combinations(ofCounts: 0...0))
108+
XCTAssertEqualSequences([[]], "".combinations(ofCount: 0...0))
109109
XCTAssertEqualSequences([[]], "ABCD".combinations(ofCount: 0))
110-
XCTAssertEqualSequences([[]], "ABCD".combinations(ofCounts: 0...0))
110+
XCTAssertEqualSequences([[]], "ABCD".combinations(ofCount: 0...0))
111111

112112
// `k` greater than element count results in zero combinations
113113
XCTAssertEqualSequences([], "".combinations(ofCount: 5))
114-
XCTAssertEqualSequences([], "".combinations(ofCounts: 5...10))
114+
XCTAssertEqualSequences([], "".combinations(ofCount: 5...10))
115115
XCTAssertEqualSequences([], "ABCD".combinations(ofCount: 5))
116-
XCTAssertEqualSequences([], "ABCD".combinations(ofCounts: 5...10))
116+
XCTAssertEqualSequences([], "ABCD".combinations(ofCount: 5...10))
117117
}
118118

119119
func testCombinationsLazy() {
120120
XCTAssertLazySequence("ABC".lazy.combinations(ofCount: 1))
121-
XCTAssertLazySequence("ABC".lazy.combinations(ofCounts: 1...3))
122-
XCTAssertLazySequence("ABC".lazy.combinations(ofCounts: 1...))
123-
XCTAssertLazySequence("ABC".lazy.combinations(ofCounts: ...3))
124-
XCTAssertLazySequence("ABC".lazy.combinations(ofCounts: 0...))
121+
XCTAssertLazySequence("ABC".lazy.combinations(ofCount: 1...3))
122+
XCTAssertLazySequence("ABC".lazy.combinations(ofCount: 1...))
123+
XCTAssertLazySequence("ABC".lazy.combinations(ofCount: ...3))
124+
XCTAssertLazySequence("ABC".lazy.combinations(ofCount: 0...))
125125
}
126126
}

0 commit comments

Comments
 (0)