File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,55 @@ where Self: BidirectionalCollection, Element: Comparable
249
249
//===----------------------------------------------------------------------===//
250
250
251
251
extension Collection {
252
+ /// Returns a collection of the permutations of this collection with lengths
253
+ /// in the specified range.
254
+ ///
255
+ /// This example prints the different permutations of one to two elements from
256
+ /// an array of three names:
257
+ ///
258
+ /// let names = ["Alex", "Celeste", "Davide"]
259
+ /// for perm in names.permutations(ofCount: 1...2) {
260
+ /// print(perm.joined(separator: ", "))
261
+ /// }
262
+ /// // Alex
263
+ /// // Celeste
264
+ /// // Davide
265
+ /// // Alex, Celeste
266
+ /// // Alex, Davide
267
+ /// // Celeste, Alex
268
+ /// // Celeste, Davide
269
+ /// // Davide, Alex
270
+ /// // Davide, Celeste
271
+ ///
272
+ /// This example prints _all_ the permutations (including an empty array) from
273
+ /// the an array of numbers:
274
+ ///
275
+ /// let numbers = [10, 20, 30]
276
+ /// for perm in numbers.permutations(ofCount: 0...) {
277
+ /// print(perm)
278
+ /// }
279
+ /// // []
280
+ /// // [10]
281
+ /// // [20]
282
+ /// // [30]
283
+ /// // [10, 20]
284
+ /// // [10, 30]
285
+ /// // [20, 10]
286
+ /// // [20, 30]
287
+ /// // [30, 10]
288
+ /// // [30, 20]
289
+ /// // [10, 20, 30]
290
+ /// // [10, 30, 20]
291
+ /// // [20, 10, 30]
292
+ /// // [20, 30, 10]
293
+ /// // [30, 10, 20]
294
+ /// // [30, 20, 10]
295
+ ///
296
+ /// - Parameter kRange: The number of elements to include in each permutation.
297
+ ///
298
+ /// - Complexity: O(1) for random-access base collections. O(*n*) where *n*
299
+ /// is the number of elements in the base collection, since `Permutations`
300
+ /// accesses the `count` of the base collection.
252
301
@inlinable
253
302
public func permutations< R: RangeExpression > (
254
303
ofCount kRange: R
You can’t perform that action at this time.
0 commit comments