Skip to content

Commit 15c18a2

Browse files
committed
Document range-based permutations(ofCount:) in Guides/Permutations.md
1 parent 4ca1a21 commit 15c18a2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Guides/Permutations.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ for perm in numbers2.permutations() {
6060
// [10, 10, 20]
6161
```
6262

63+
Given a range, the `permutations(ofCount:)` method returns a sequence of all the different permutations of the given sizes of a collection’s elements in increasing order of size.
64+
65+
```swift
66+
let numbers = [10, 20, 30]
67+
for perm in numbers.permutations(ofCount: 0...) {
68+
print(perm)
69+
}
70+
// []
71+
// [10]
72+
// [20]
73+
// [30]
74+
// [10, 20]
75+
// [10, 30]
76+
// [20, 10]
77+
// [20, 30]
78+
// [30, 10]
79+
// [30, 20]
80+
// [10, 20, 30]
81+
// [10, 30, 20]
82+
// [20, 10, 30]
83+
// [20, 30, 10]
84+
// [30, 10, 20]
85+
// [30, 20, 10]
86+
```
87+
6388
## Detailed Design
6489

6590
The `permutations(ofCount:)` method is declared as a `Collection` extension,

0 commit comments

Comments
 (0)