Skip to content

Commit b7dad9b

Browse files
authored
Merge pull request #2809 from amritpan/amend
[SE-0479] Amend Motivation text and add Future Directions.
2 parents 0635c7d + d62a69b commit b7dad9b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

proposals/0479-method-and-initializer-keypaths.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Swift key paths can be written to properties and subscripts. This proposal exten
1414

1515
## Motivation
1616

17-
Key paths to method members and their advantages have been explored in several discussions on the Swift forum, specifically to [unapplied instance methods](https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582) and to [partially and applied methods](https://forums.swift.org/t/pitch-allow-keypaths-to-represent-functions/67630). Extending key paths to include reference to methods and initializers and handling them similarly to properties and subscripts will unify instance and type member access for a more consistent API. Key path methods and initializers will also enjoy all of the benefits offered by existing key path component kinds, e.g. simplify code by abstracting away details of how these properties/subscripts/methods are modified/accessed/invoked, reusability via generic functions that accept key paths to methods as parameters, and supporting dynamic invocation while maintaining type safety.
17+
Key paths to method members and their advantages have been explored in several discussions on the Swift forum, specifically to [unapplied instance methods](https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582) and to [partially and applied methods](https://forums.swift.org/t/pitch-allow-keypaths-to-represent-functions/67630). Extending key paths to include reference to methods and initializers and handling them similarly to properties and subscripts will unify instance and type member access for a more consistent API. While this does not yet encompass all method kinds, particularly those with effectful or non-hashable arguments, it lays the groundwork for more expressive, type-safe APIs. In doing so, it brings many of the benefits of existing key path components to supported methods and initializers, such as abstraction, reusability via generic functions and dynamic invocation with state type safety.
1818

1919
## Proposed solution
2020

@@ -142,8 +142,8 @@ struct DynamicKeyPathWrapper<Root> {
142142
}
143143

144144
let dynamicCalculator = DynamicKeyPathWrapper(root: Calculator())
145-
let subtract = dynamicCalculator.subtract
146-
print(subtract(10))
145+
let power = dynamicCalculator.power
146+
print(power(10, 2))
147147
```
148148

149149
### Effectful value types
@@ -170,3 +170,7 @@ This feature does not affect ABI compatibility.
170170
## Implications on adoption
171171

172172
This feature has no implications on adoption.
173+
174+
## Future directions
175+
176+
The effectful value types that are unsupported by this feature will all require new `KeyPath` types and so have been left out of this proposal. Additionally, this lack of support impacts existing key path component kinds and could be addressed in a unified proposal that resolves this gap across all key path component kinds.

0 commit comments

Comments
 (0)