Skip to content

Commit 4f3daca

Browse files
committed
[SR-4005] Allow heterogenous comparisons in elementsEqual
When a user is supplying a predicate to compare the type equivalence isn’t required
1 parent bd0a683 commit 4f3daca

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

stdlib/public/core/SequenceAlgorithms.swift.gyb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,14 @@ ${equivalenceExplanation}
338338
public func elementsEqual<OtherSequence>(
339339
_ other: OtherSequence${"," if preds else ""}
340340
% if preds:
341-
by areEquivalent: (Element, Element) throws -> Bool
341+
by areEquivalent: (Element, OtherSequence.Element) throws -> Bool
342342
% end
343343
) ${rethrows_}-> Bool
344344
where
345-
OtherSequence: Sequence,
345+
OtherSequence: Sequence${" {" if preds else ","}
346+
% if not preds:
346347
OtherSequence.Element == Element {
348+
% end
347349
348350
var iter1 = self.makeIterator()
349351
var iter2 = other.makeIterator()

test/IDE/complete_from_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func testArchetypeReplacement3 (_ a : [Int]) {
170170
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceVar]/Super: first[#Int?#]
171171
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: map({#(transform): (Int) throws -> T##(Int) throws -> T#})[' rethrows'][#[T]#]
172172
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropLast({#(n): Int#})[#ArraySlice<Int>#]
173-
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#by: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
173+
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#by: (Int, IteratorProtocol.Element) throws -> Bool##(Int, IteratorProtocol.Element) throws -> Bool#})[' rethrows'][#Bool#]
174174

175175

176176
protocol P2 {

test/api-digester/source-stability.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ Func ReversedRandomAccessCollection.index(_:offsetBy:) has return type change fr
328328
Func ReversedRandomAccessCollection.index(_:offsetBy:limitedBy:) has return type change from ReversedRandomAccessIndex<Base>? to ReversedRandomAccessCollection.Index?
329329
Func ReversedRandomAccessCollection.index(after:) has return type change from ReversedRandomAccessIndex<Base> to ReversedRandomAccessCollection.Index
330330
Func ReversedRandomAccessCollection.index(before:) has return type change from ReversedRandomAccessIndex<Base> to ReversedRandomAccessCollection.Index
331+
Func Sequence.elementsEqual(_:by:) has 2nd parameter type change from (Self.Iterator.Element, Self.Iterator.Element) throws -> Bool to (Self.Iterator.Element, OtherSequence.Iterator.Element) throws -> Bool
331332
Func Set.formSymmetricDifference(_:) has parameter 0 type change from Set<Element> to Set<Set.Element>
332333
Func Set.index(after:) has return type change from SetIndex<Element> to Set<Element>.Index
333334
Func Set.index(of:) has return type change from SetIndex<Element>? to Set<Element>.Index?

0 commit comments

Comments
 (0)