anandabits
(Matthew Johnson)
June 28, 2020, 3:10pm
14
Jumhyn:
I'm not troubled by that, really, since already members with compound names and bound methods would be accessed via the same syntax:
struct S {
var f(x:): (Int) -> Void = {}
func g(x: Int) {}
}
let f = S().f(x:)
let g = S().g(x:)
This uses different syntax which does not involve key paths. It wouldn’t make sense to access an unbound method from an instance like this. The syntax that has been discussed has always been using keypath syntax.
Here are a couple of threads that have included discussions of this feature:
Introduction
In SE-0042 @Joe_Groff introduced the idea of flattening unapplied method references (UMRs), from the curried form to a function with an additional Self parameter (the details can be found in the proposal - it's a quick and easy read). This proposal was accepted, yet never implemented.
A benefit resulting from this change would be a massive improvement when passing around methods as function parameters. As Joe Groff himself puts it:
For instance, though you can pass the global + …
Allow key paths to reference unapplied instance methods
The original key path proposal expressly limited key paths to be able to reference only properties and subscripts:
\Person.name // KeyPath<Person, String>
\Person.pets[0] // KeyPath<Person, Pet>
This proposal adds the ability for key paths to reference instance methods, optionally specifying argument names:
\Person.sing // KeyPath<Person, () -> Sound>
\Person.sing(melody:lyrics:) // KeyP…
1 Like