[OrderedSet] Add OrderedSet.appending(contentsOf:)
#452
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new public function on
appending(contentsOf:)
toOrderedSet
. It is functionally equivalent tounion(_:)
but is more explicit about ordering. I find myself looking for this, rather thanunion
because a mutatingappend(contentsOf:)
already exists.A counter argument to this addition would be to minimize duplicative APIs as much as possible to reduce API surface area. However, there's already precedent for "alternative" functions, given
append(contentsOf:)
andformUnion(_:)
coexist. And in this case I believe it adds sufficient value to justify the addition.It's second nature to look for an "append" on ordered collections in Swift. Arrays are ubiquitous and an
append(contentsOf:)
exists. However, unlike Array, OrderedSet does not support the+
operator, so adding this as an alternative tounion(_:)
seems to fill a gap.Detailed Design
The implementation is simple, copying the instance to a mutable value then calling
append(contentsOf:)
and returning the result. This is the same pattern to howunion(_:)
works.Documentation
Symbol-level documentation has been added but I don't think it's necessary to update any guides, since this isn't adding any new functionality.
Testing
A new
test_appending_Self
has been addedPerformance
Not profiled.
Source Impact
What is the impact of this change on existing users of this package? Does it deprecate or remove any existing API?
Checklist