@@ -1354,24 +1354,112 @@ func _projectKeyPathReferenceWritable<Root, Value>(
1354
1354
public protocol _AppendKeyPath { }
1355
1355
1356
1356
extension _AppendKeyPath where Self == AnyKeyPath {
1357
+ /// Returns a new key path created by appending the given key path to this
1358
+ /// one.
1359
+ ///
1360
+ /// Use this method to extend this key path to the value type of another key
1361
+ /// path. Appending the key path passed as `path` is successful only if the
1362
+ /// root type for `path` matches this key path's value type. This example
1363
+ /// creates key paths from `Array<Int>` to `String` and from `String` to
1364
+ /// `Int`, and then tries appending each to the other:
1365
+ ///
1366
+ /// let arrayDescription: AnyKeyPath = \Array<Int>.description
1367
+ /// let stringLength: AnyKeyPath = \String.count
1368
+ ///
1369
+ /// // Creates a key path from `Array<Int>` to `Int`
1370
+ /// let arrayDescriptionLength = arrayDescription.appending(path: stringLength)
1371
+ ///
1372
+ /// let invalidKeyPath = stringLength.appending(path: arrayDescription)
1373
+ /// // invalidKeyPath == nil
1374
+ ///
1375
+ /// The second call to `appending(path:)` returns `nil`
1376
+ /// because the root type of `arrayDescription`, `Array<Int>`, does not
1377
+ /// match the value type of `stringLength`, `Int`.
1378
+ ///
1379
+ /// - Parameter path: The key path to append.
1380
+ /// - Returns: A key path from the root of this key path and the value type
1381
+ /// of `path`, if `path` can be appended. If `path` can't be appended,
1382
+ /// returns `nil`.
1357
1383
public func appending( path: AnyKeyPath ) -> AnyKeyPath ? {
1358
1384
return _tryToAppendKeyPaths ( root: self , leaf: path)
1359
1385
}
1360
1386
}
1361
1387
1362
1388
extension _AppendKeyPath /* where Self == PartialKeyPath<T> */ {
1389
+ /// Returns a new key path created by appending the given key path to this
1390
+ /// one.
1391
+ ///
1392
+ /// Use this method to extend this key path to the value type of another key
1393
+ /// path. Appending the key path passed as `path` is successful only if the
1394
+ /// root type for `path` matches this key path's value type. This example
1395
+ /// creates key paths from `Array<Int>` to `String` and from `String` to
1396
+ /// `Int`, and then tries appending each to the other:
1397
+ ///
1398
+ /// let arrayDescription: PartialKeyPath<Array<Int>> = \.description
1399
+ /// let stringLength: PartialKeyPath<String> = \.count
1400
+ ///
1401
+ /// // Creates a key path from `Array<Int>` to `Int`
1402
+ /// let arrayDescriptionLength = arrayDescription.appending(path: stringLength)
1403
+ ///
1404
+ /// let invalidKeyPath = stringLength.appending(path: arrayDescription)
1405
+ /// // invalidKeyPath == nil
1406
+ ///
1407
+ /// The second call to `appending(path:)` returns `nil`
1408
+ /// because the root type of `arrayDescription`, `Array<Int>`, does not
1409
+ /// match the value type of `stringLength`, `Int`.
1410
+ ///
1411
+ /// - Parameter path: The key path to append.
1412
+ /// - Returns: A key path from the root of this key path and the value type
1413
+ /// of `path`, if `path` can be appended. If `path` can't be appended,
1414
+ /// returns `nil`.
1363
1415
public func appending< Root> ( path: AnyKeyPath ) -> PartialKeyPath < Root > ?
1364
1416
where Self == PartialKeyPath < Root > {
1365
1417
return _tryToAppendKeyPaths ( root: self , leaf: path)
1366
1418
}
1367
1419
1420
+ /// Returns a new key path created by appending the given key path to this
1421
+ /// one.
1422
+ ///
1423
+ /// Use this method to extend this key path to the value type of another key
1424
+ /// path. Appending the key path passed as `path` is successful only if the
1425
+ /// root type for `path` matches this key path's value type. This example
1426
+ /// creates a key path from `Array<Int>` to `String`, and then tries
1427
+ /// appending compatible and incompatible key paths:
1428
+ ///
1429
+ /// let arrayDescription: PartialKeyPath<Array<Int>> = \.description
1430
+ ///
1431
+ /// // Creates a key path from `Array<Int>` to `Int`
1432
+ /// let arrayDescriptionLength = arrayDescription.appending(path: \String.count)
1433
+ ///
1434
+ /// let invalidKeyPath = arrayDescription.appending(path: \Double.isZero)
1435
+ /// // invalidKeyPath == nil
1436
+ ///
1437
+ /// The second call to `appending(path:)` returns `nil` because the root type
1438
+ /// of the `path` parameter, `Double`, does not match the value type of
1439
+ /// `arrayDescription`, `String`.
1440
+ ///
1441
+ /// - Parameter path: The key path to append.
1442
+ /// - Returns: A key path from the root of this key path to the the value type
1443
+ /// of `path`, if `path` can be appended. If `path` can't be appended,
1444
+ /// returns `nil`.
1368
1445
public func appending< Root, AppendedRoot, AppendedValue> (
1369
1446
path: KeyPath < AppendedRoot , AppendedValue >
1370
1447
) -> KeyPath < Root , AppendedValue > ?
1371
1448
where Self == PartialKeyPath < Root > {
1372
1449
return _tryToAppendKeyPaths ( root: self , leaf: path)
1373
1450
}
1374
1451
1452
+ /// Returns a new key path created by appending the given key path to this
1453
+ /// one.
1454
+ ///
1455
+ /// Use this method to extend this key path to the value type of another key
1456
+ /// path. Appending the key path passed as `path` is successful only if the
1457
+ /// root type for `path` matches this key path's value type.
1458
+ ///
1459
+ /// - Parameter path: The reference writeable key path to append.
1460
+ /// - Returns: A key path from the root of this key path to the the value type
1461
+ /// of `path`, if `path` can be appended. If `path` can't be appended,
1462
+ /// returns `nil`.
1375
1463
public func appending< Root, AppendedRoot, AppendedValue> (
1376
1464
path: ReferenceWritableKeyPath < AppendedRoot , AppendedValue >
1377
1465
) -> ReferenceWritableKeyPath < Root , AppendedValue > ?
@@ -1381,6 +1469,22 @@ extension _AppendKeyPath /* where Self == PartialKeyPath<T> */ {
1381
1469
}
1382
1470
1383
1471
extension _AppendKeyPath /* where Self == KeyPath<T,U> */ {
1472
+ /// Returns a new key path created by appending the given key path to this
1473
+ /// one.
1474
+ ///
1475
+ /// Use this method to extend this key path to the value type of another key
1476
+ /// path. Calling `appending(path:)` results in the same key path as if the
1477
+ /// given key path had been specified using dot notation. In the following
1478
+ /// example, `keyPath1` and `keyPath2` are equivalent:
1479
+ ///
1480
+ /// let arrayDescription = \Array<Int>.description
1481
+ /// let keyPath1 = arrayDescription.appending(path: \String.count)
1482
+ ///
1483
+ /// let keyPath2 = \Array<Int>.description.count
1484
+ ///
1485
+ /// - Parameter path: The key path to append.
1486
+ /// - Returns: A key path from the root of this key path to the value type of
1487
+ /// `path`.
1384
1488
public func appending< Root, Value, AppendedValue> (
1385
1489
path: KeyPath < Value , AppendedValue >
1386
1490
) -> KeyPath < Root , AppendedValue >
@@ -1399,6 +1503,16 @@ extension _AppendKeyPath /* where Self == KeyPath<T,U> */ {
1399
1503
}
1400
1504
*/
1401
1505
1506
+ /// Returns a new key path created by appending the given key path to this
1507
+ /// one.
1508
+ ///
1509
+ /// Use this method to extend this key path to the value type of another key
1510
+ /// path. Calling `appending(path:)` results in the same key path as if the
1511
+ /// given key path had been specified using dot notation.
1512
+ ///
1513
+ /// - Parameter path: The key path to append.
1514
+ /// - Returns: A key path from the root of this key path to the value type of
1515
+ /// `path`.
1402
1516
public func appending< Root, Value, AppendedValue> (
1403
1517
path: ReferenceWritableKeyPath < Value , AppendedValue >
1404
1518
) -> ReferenceWritableKeyPath < Root , AppendedValue >
@@ -1408,13 +1522,33 @@ extension _AppendKeyPath /* where Self == KeyPath<T,U> */ {
1408
1522
}
1409
1523
1410
1524
extension _AppendKeyPath /* where Self == WritableKeyPath<T,U> */ {
1525
+ /// Returns a new key path created by appending the given key path to this
1526
+ /// one.
1527
+ ///
1528
+ /// Use this method to extend this key path to the value type of another key
1529
+ /// path. Calling `appending(path:)` results in the same key path as if the
1530
+ /// given key path had been specified using dot notation.
1531
+ ///
1532
+ /// - Parameter path: The key path to append.
1533
+ /// - Returns: A key path from the root of this key path to the value type of
1534
+ /// `path`.
1411
1535
public func appending< Root, Value, AppendedValue> (
1412
1536
path: WritableKeyPath < Value , AppendedValue >
1413
1537
) -> WritableKeyPath < Root , AppendedValue >
1414
1538
where Self == WritableKeyPath < Root , Value > {
1415
1539
return _appendingKeyPaths ( root: self , leaf: path)
1416
1540
}
1417
1541
1542
+ /// Returns a new key path created by appending the given key path to this
1543
+ /// one.
1544
+ ///
1545
+ /// Use this method to extend this key path to the value type of another key
1546
+ /// path. Calling `appending(path:)` results in the same key path as if the
1547
+ /// given key path had been specified using dot notation.
1548
+ ///
1549
+ /// - Parameter path: The key path to append.
1550
+ /// - Returns: A key path from the root of this key path to the value type of
1551
+ /// `path`.
1418
1552
public func appending< Root, Value, AppendedValue> (
1419
1553
path: ReferenceWritableKeyPath < Value , AppendedValue >
1420
1554
) -> ReferenceWritableKeyPath < Root , AppendedValue >
@@ -1424,6 +1558,16 @@ extension _AppendKeyPath /* where Self == WritableKeyPath<T,U> */ {
1424
1558
}
1425
1559
1426
1560
extension _AppendKeyPath /* where Self == ReferenceWritableKeyPath<T,U> */ {
1561
+ /// Returns a new key path created by appending the given key path to this
1562
+ /// one.
1563
+ ///
1564
+ /// Use this method to extend this key path to the value type of another key
1565
+ /// path. Calling `appending(path:)` results in the same key path as if the
1566
+ /// given key path had been specified using dot notation.
1567
+ ///
1568
+ /// - Parameter path: The key path to append.
1569
+ /// - Returns: A key path from the root of this key path to the value type of
1570
+ /// `path`.
1427
1571
public func appending< Root, Value, AppendedValue> (
1428
1572
path: WritableKeyPath < Value , AppendedValue >
1429
1573
) -> ReferenceWritableKeyPath < Root , AppendedValue >
0 commit comments