You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/NNNN-add-is-identical-methods.md
+86-6Lines changed: 86 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -393,7 +393,13 @@ When we build and run our SwiftUI app we confirm that we are not computing new `
393
393
394
394
We propose adding `isIdentical` methods to the following concrete types from Standard Library:
395
395
*`String`
396
+
*`String.UnicodeScalarView`
397
+
*`String.UTF16View`
398
+
*`String.UTF8View`
396
399
*`Substring`
400
+
*`Substring.UnicodeScalarView`
401
+
*`Substring.UTF16View`
402
+
*`Substring.UTF8View`
397
403
*`Array`
398
404
*`ArraySlice`
399
405
*`ContiguousArray`
@@ -419,6 +425,16 @@ extension String {
419
425
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
420
426
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
421
427
/// - `a.isIdentical(b)` implies `a == b`
428
+
/// - `a == b` does not imply `a.isIdentical(b)`
429
+
///
430
+
/// Values produced by copying the same value, with no intervening mutations,
431
+
/// will compare identical:
432
+
///
433
+
/// ```swift
434
+
/// let d = c
435
+
/// print(c.isIdentical(to: d))
436
+
/// // Prints true
437
+
/// ```
422
438
///
423
439
/// Comparing strings this way includes comparing (normally) hidden
424
440
/// implementation details such as the memory location of any underlying
@@ -431,6 +447,11 @@ extension String {
431
447
}
432
448
```
433
449
450
+
The following types will adopt the same semantic guarantees as `String`:
451
+
*`String.UnicodeScalarView`
452
+
*`String.UTF16View`
453
+
*`String.UTF8View`
454
+
434
455
### `Substring`
435
456
436
457
```swift
@@ -448,6 +469,16 @@ extension Substring {
448
469
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
449
470
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
450
471
/// - `a.isIdentical(b)` implies `a == b`
472
+
/// - `a == b` does not imply `a.isIdentical(b)`
473
+
///
474
+
/// Values produced by copying the same value, with no intervening mutations,
475
+
/// will compare identical:
476
+
///
477
+
/// ```swift
478
+
/// let d = c
479
+
/// print(c.isIdentical(to: d))
480
+
/// // Prints true
481
+
/// ```
451
482
///
452
483
/// Comparing substrings this way includes comparing (normally) hidden
453
484
/// implementation details such as the memory location of any underlying
@@ -460,6 +491,11 @@ extension Substring {
460
491
}
461
492
```
462
493
494
+
The following types will adopt the same semantic guarantees as `Substring`:
495
+
*`Substring.UnicodeScalarView`
496
+
*`Substring.UTF16View`
497
+
*`Substring.UTF8View`
498
+
463
499
### `Array`
464
500
465
501
```swift
@@ -477,6 +513,16 @@ extension Array {
477
513
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
478
514
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
479
515
/// - If `a` and `b` are `Equatable`, then `a.isIdentical(b)` implies `a == b`
516
+
/// - `a == b` does not imply `a.isIdentical(b)`
517
+
///
518
+
/// Values produced by copying the same value, with no intervening mutations,
519
+
/// will compare identical:
520
+
///
521
+
/// ```swift
522
+
/// let d = c
523
+
/// print(c.isIdentical(to: d))
524
+
/// // Prints true
525
+
/// ```
480
526
///
481
527
/// Comparing arrays this way includes comparing (normally) hidden
482
528
/// implementation details such as the memory location of any underlying
@@ -506,6 +552,16 @@ extension ArraySlice {
506
552
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
507
553
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
508
554
/// - If `a` and `b` are `Equatable`, then `a.isIdentical(b)` implies `a == b`
555
+
/// - `a == b` does not imply `a.isIdentical(b)`
556
+
///
557
+
/// Values produced by copying the same value, with no intervening mutations,
558
+
/// will compare identical:
559
+
///
560
+
/// ```swift
561
+
/// let d = c
562
+
/// print(c.isIdentical(to: d))
563
+
/// // Prints true
564
+
/// ```
509
565
///
510
566
/// Comparing arrays this way includes comparing (normally) hidden
511
567
/// implementation details such as the memory location of any underlying
@@ -535,6 +591,16 @@ extension ContiguousArray {
535
591
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
536
592
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
537
593
/// - If `a` and `b` are `Equatable`, then `a.isIdentical(b)` implies `a == b`
594
+
/// - `a == b` does not imply `a.isIdentical(b)`
595
+
///
596
+
/// Values produced by copying the same value, with no intervening mutations,
597
+
/// will compare identical:
598
+
///
599
+
/// ```swift
600
+
/// let d = c
601
+
/// print(c.isIdentical(to: d))
602
+
/// // Prints true
603
+
/// ```
538
604
///
539
605
/// Comparing arrays this way includes comparing (normally) hidden
540
606
/// implementation details such as the memory location of any underlying
@@ -564,6 +630,16 @@ extension Dictionary {
564
630
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
565
631
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
566
632
/// - If `a` and `b` are `Equatable`, then `a.isIdentical(b)` implies `a == b`
633
+
/// - `a == b` does not imply `a.isIdentical(b)`
634
+
///
635
+
/// Values produced by copying the same value, with no intervening mutations,
636
+
/// will compare identical:
637
+
///
638
+
/// ```swift
639
+
/// let d = c
640
+
/// print(c.isIdentical(to: d))
641
+
/// // Prints true
642
+
/// ```
567
643
///
568
644
/// Comparing dictionaries this way includes comparing (normally) hidden
569
645
/// implementation details such as the memory location of any underlying
@@ -593,6 +669,16 @@ extension Set {
593
669
/// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
594
670
/// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
595
671
/// - `a.isIdentical(b)` implies `a == b`
672
+
/// - `a == b` does not imply `a.isIdentical(b)`
673
+
///
674
+
/// Values produced by copying the same value, with no intervening mutations,
675
+
/// will compare identical:
676
+
///
677
+
/// ```swift
678
+
/// let d = c
679
+
/// print(c.isIdentical(to: d))
680
+
/// // Prints true
681
+
/// ```
596
682
///
597
683
/// Comparing sets this way includes comparing (normally) hidden
598
684
/// implementation details such as the memory location of any underlying set
@@ -622,12 +708,6 @@ Any Standard Library types that are copy-on-write values could be good candidate
622
708
*`KeyValuePairs`
623
709
*`StaticBigInt`
624
710
*`StaticString`
625
-
*`String.UnicodeScalarView`
626
-
*`String.UTF16View`
627
-
*`String.UTF8View`
628
-
*`Substring.UnicodeScalarView`
629
-
*`Substring.UTF16View`
630
-
*`Substring.UTF8View`
631
711
*`UTF8Span`
632
712
633
713
This proposal focuses on what we see as the most high-impact types to support from Standard Library. This proposal *is not* meant to discourage adding `isIdentical(to:)` on any of these types at some point in the future. A follow-up “second-round” proposal could focus on these remaining types.
0 commit comments