-
Notifications
You must be signed in to change notification settings - Fork 448
Add uniquePermutations as wrapper for nextPermutation #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think we actually want I just wanted this for #107 where I wrote: var tests: [[Int?]] = [
[],
[0],
[nil],
[0, nil],
[nil, 0],
[0, nil, 1, nil, 2, nil],
[0, 1, 2, nil, nil, nil],
[nil, nil, nil, 0, 1, 2],
] I would have preferred to write: let tests = [nil, nil, nil, 0, 1, 2].uniquePermutations(ofCount: 0) ... which also would have given me more exhaustive test coverage. |
Totally agreed, though that points to the need for a let tests = [nil, nil, nil, 0, 1, 2]
.uniquePermutations(ofCount: 0...) { lhs, rhs in
rhs.map { rhs in lhs.map { lhs in lhs < rhs } ?? true } ?? false
} |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
2ff5a19
to
461208a
Compare
@swift-ci Please test |
Co-authored-by: Tim Vermeulen <[email protected]>
@swift-ci Please test |
Description
Adds methods for generating the unique permutations of a sequence, as distinct from the position-based permutations generated by
permutations()
.Detailed Design
Includes new
uniquePermutations(ofCount:)
methods (for both single counts and range expressions) and the wrappingUniquePermutations
type. The method requires that a collection's elements be hashable so that uniqueness can be determined in a pre-processing pass:Documentation Plan
I've added API documentation on the new methods and type, and have updated
Permutations.md
to include information about unique permutations.Test Plan
I've created tests in the
UniquePermutationsTests.swift
file.Source Impact
None, additive only.
Checklist