Skip to content

Commit a216755

Browse files
author
Dave Abrahams
committed
isEquivalent: => comparingBy areEquivalent:
fixup! isEquivalent: => testingEquivalenceWith predicate:
1 parent f510d93 commit a216755

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ public func expectEqualSequence<
21912191
) where
21922192
Expected.Iterator.Element == Actual.Iterator.Element {
21932193

2194-
if !expected.elementsEqual(actual, isEquivalent: sameValue) {
2194+
if !expected.elementsEqual(actual, comparingBy: sameValue) {
21952195
expectationFailure("expected elements: \"\(expected)\"\n"
21962196
+ "actual: \"\(actual)\" (of type \(String(reflecting: actual.dynamicType)))",
21972197
trace: ${trace})

stdlib/public/core/SequenceAlgorithms.swift.gyb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ equivalenceExplanation = """\
3636
/// is, for any elements `a`, `b`, and `c`, the following conditions must
3737
/// hold:
3838
///
39-
/// - `isEquivalent(a, a)` is always `true`. (Reflexivity)
40-
/// - `isEquivalent(a, b)` implies `isEquivalent(b, a)`. (Symmetry)
41-
/// - If `isEquivalent(a, b)` and `isEquivalent(b, c)` are both `true`, then
42-
/// `isEquivalent(a, c)` is also `true`. (Transitivity)
39+
/// - `areEquivalent(a, a)` is always `true`. (Reflexivity)
40+
/// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry)
41+
/// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then
42+
/// `areEquivalent(a, c)` is also `true`. (Transitivity)
4343
///"""
4444

4545
}%
@@ -209,7 +209,7 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
209209
${equivalenceExplanation}
210210
/// - Parameters:
211211
/// - possiblePrefix: A sequence to compare to this sequence.
212-
/// - isEquivalent: A predicate that returns `true` if its two arguments
212+
/// - areEquivalent: A predicate that returns `true` if its two arguments
213213
/// are equivalent; otherwise, `false`.
214214
/// - Returns: `true` if the initial elements of the sequence are equivalent
215215
/// to the elements of `possiblePrefix`; otherwise, `false`. Returns
@@ -235,12 +235,12 @@ ${equivalenceExplanation}
235235
/// the elements of `possiblePrefix`; otherwise, `false`. Returns `true`
236236
/// if `possiblePrefix` has no elements.
237237
///
238-
/// - SeeAlso: `starts(with:isEquivalent:)`
238+
/// - SeeAlso: `starts(with:comparingBy:)`
239239
% end
240240
public func starts<PossiblePrefix>(
241241
with possiblePrefix: PossiblePrefix${"," if preds else ""}
242242
% if preds:
243-
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
243+
comparingBy areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
244244
% end
245245
) ${rethrows_}-> Bool
246246
where
@@ -250,7 +250,7 @@ ${equivalenceExplanation}
250250
var possiblePrefixIterator = possiblePrefix.makeIterator()
251251
for e0 in self {
252252
if let e1 = possiblePrefixIterator.next() {
253-
if ${"try !isEquivalent(e0, e1)" if preds else "e0 != e1"} {
253+
if ${"try !areEquivalent(e0, e1)" if preds else "e0 != e1"} {
254254
return false
255255
}
256256
}
@@ -285,10 +285,10 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
285285
${equivalenceExplanation}
286286
/// - Parameters:
287287
/// - other: A sequence to compare to this sequence.
288-
/// - isEquivalent: A predicate that returns `true` if its two arguments
288+
/// - areEquivalent: A predicate that returns `true` if its two arguments
289289
/// are equivalent; otherwise, `false`.
290290
/// - Returns: `true` if this sequence and `other` contain equivalent items,
291-
/// using `isEquivalent` as the equivalence test; otherwise, `false.`
291+
/// using `areEquivalent` as the equivalence test; otherwise, `false.`
292292
///
293293
/// - SeeAlso: `elementsEqual(_:)`
294294
% else:
@@ -311,12 +311,12 @@ ${equivalenceExplanation}
311311
/// - Returns: `true` if this sequence and `other` contain the same elements
312312
/// in the same order.
313313
///
314-
/// - SeeAlso: `elementsEqual(_:isEquivalent:)`
314+
/// - SeeAlso: `elementsEqual(_:comparingBy:)`
315315
% end
316316
public func elementsEqual<OtherSequence>(
317317
_ other: OtherSequence${"," if preds else ""}
318318
% if preds:
319-
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
319+
comparingBy areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
320320
% end
321321
) ${rethrows_}-> Bool
322322
where
@@ -328,7 +328,7 @@ ${equivalenceExplanation}
328328
while true {
329329
switch (iter1.next(), iter2.next()) {
330330
case let (e1?, e2?):
331-
if ${'try !isEquivalent(e1, e2)' if preds else 'e1 != e2'} {
331+
if ${'try !areEquivalent(e1, e2)' if preds else 'e1 != e2'} {
332332
return false
333333
}
334334
case (_?, nil),
@@ -692,9 +692,9 @@ extension Sequence {
692692
Builtin.unreachable()
693693
}
694694

695-
@available(*, unavailable, renamed: "starts")
695+
@available(*, unavailable, renamed: "starts(with:comparingBy:)")
696696
public func startsWith<PossiblePrefix>(
697-
with possiblePrefix: PossiblePrefix,
697+
_ possiblePrefix: PossiblePrefix,
698698
isEquivalent: @noescape (Iterator.Element, Iterator.Element) throws -> Bool
699699
) rethrows-> Bool
700700
where
@@ -728,9 +728,9 @@ extension Sequence where Iterator.Element : Comparable {
728728
Builtin.unreachable()
729729
}
730730

731-
@available(*, unavailable, renamed: "starts")
731+
@available(*, unavailable, renamed: "starts(with:)")
732732
public func startsWith<PossiblePrefix>(
733-
with possiblePrefix: PossiblePrefix
733+
_ possiblePrefix: PossiblePrefix
734734
) -> Bool
735735
where
736736
PossiblePrefix : Sequence,

test/1_stdlib/StringAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ func checkHasPrefixHasSuffix(
240240
Array(String($0).unicodeScalars)
241241
}
242242
let expectHasPrefix = lhsNFDGraphemeClusters.starts(
243-
with: rhsNFDGraphemeClusters, isEquivalent: (==))
243+
with: rhsNFDGraphemeClusters, comparingBy: (==))
244244

245245
let expectHasSuffix = lhsNFDGraphemeClusters.lazy.reversed()
246-
.starts(with: rhsNFDGraphemeClusters.lazy.reversed(), isEquivalent: (==))
246+
.starts(with: rhsNFDGraphemeClusters.lazy.reversed(), comparingBy: (==))
247247

248248
expectEqual(expectHasPrefix, lhs.hasPrefix(rhs), stackTrace: stackTrace)
249249
expectEqual(
@@ -411,7 +411,7 @@ CStringTests.test("String(cString:)") {
411411
CStringTests.test("String.decodeCString") {
412412
do {
413413
let s = getNullCString()
414-
let result = String.decodeCString(UnsafePointer(s), `as`: UTF8.self)
414+
let result = String.decodeCString(UnsafePointer(s), as: UTF8.self)
415415
expectEmpty(result)
416416
}
417417
do { // repairing

test/IDE/complete_from_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func testArchetypeReplacement3 (_ a : [Int]) {
166166
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropLast({#(n): Int#})[#ArraySlice<Int>#]
167167
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: dropFirst({#(n): Int#})[#AnySequence<Int>#]
168168
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: prefix({#(maxLength): Int#})[#AnySequence<Int>#]
169-
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#isEquivalent: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
169+
// PRIVATE_NOMINAL_MEMBERS_7-DAG: Decl[InstanceMethod]/Super: elementsEqual({#(other): Sequence#}, {#comparingBy: (Int, Int) throws -> Bool##(Int, Int) throws -> Bool#})[' rethrows'][#Bool#]
170170

171171

172172
protocol P2 {

0 commit comments

Comments
 (0)