[OrderedCollections] Rename OrderedSet.replace(_:at:) to replace(at:with:)

Swap the parameter order and add the `with` label so the API matches the shape of `replaceSubrange(_:with:)` on RangeReplaceableCollection, per review feedback.
This commit is contained in:
inju2403 committed 2026-07-08 17:57:15 +09:00
1 parent 95d8afe88f
commit 1f0184e99d
2 files changed
+7 -7

No files matched your search

@@ -210,7 +210,7 @@ extension OrderedSet {
/// takes over its position:
///
/// var set: OrderedSet = [1, 2, 3]
/// let old = set.replace(4, at: 1)
/// let old = set.replace(at: 1, with: 4)
/// // old == 2
/// // set is now [1, 4, 3]
///
@@ -218,20 +218,20 @@ extension OrderedSet {
/// different index triggers a runtime error, as that would introduce a
/// duplicate.
///
/// - Parameter index: The index of the member to replace. It must be a valid
/// index below `endIndex`.
///
/// - Parameter item: The element to place at `index`. It must not already be
/// a member of the set, unless it compares equal to the member currently
/// at `index`.
///
/// - Parameter index: The index of the member to replace. It must be a valid
/// index below `endIndex`.
///
/// - Returns: The original member that was replaced.
///
/// - Complexity: Expected amortized O(1), if `Element` implements
/// high-quality hashing.
@inlinable
@discardableResult
public mutating func replace(_ item: Element, at index: Int) -> Element {
public mutating func replace(at index: Int, with item: Element) -> Element {
precondition(index >= 0 && index < count, "Index out of bounds")
defer { _checkInvariants() }
let (existing, bucket) = _find(item)
@@ -575,7 +575,7 @@ class OrderedSetTests: CollectionTestCase {
var set = OrderedSet(layout: layout, contents: contents)
withHiddenCopies(if: isShared, of: &set, checker: { $0._checkInvariants() }) { set in
let new = tracker.instance(for: count + offset) // Not yet a member.
let old = set.replace(new, at: offset)
let old = set.replace(at: offset, with: new)
expectIdentical(old, contents[offset])
expectIdentical(set[offset], new)
expectEqual(set.firstIndex(of: new), offset)
@@ -604,7 +604,7 @@ class OrderedSetTests: CollectionTestCase {
withHiddenCopies(if: isShared, of: &set, checker: { $0._checkInvariants() }) { set in
// Equal to `contents[offset]`, but a distinct instance.
let new = tracker.instance(for: offset)
let old = set.replace(new, at: offset)
let old = set.replace(at: offset, with: new)
expectIdentical(old, contents[offset])
expectIdentical(set[offset], new)
expectEqualElements(set, contents)