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:) // KeyPath<Person, (Melody, String) -> Sound>
Note that these key paths do not provide argument values; they reference unapplied methods, and the value they give is a function, not the the value that results from calling the method. (See Future Directions.)
Adding this capability not only removes an inconsistency in Swift, but also solves pratical problems involving map/filter operations, proxying with key path member lookup, and passing weak method references that do not retain their receiver.
Full proposal text: Allow key paths to reference unapplied instance methods
This document is still a work in progress, but is ready for public discussion.
I expect the most controversial aspect of this proposal will not be what it includes, but rather what it leaves out. Some important problems we expressly defer to future proposals. Please see the proposal text for the rationale behind what is in and out of scope.
Thanks to @filip-sakel and @Saklad5 for their contributions to the writing and example code, as well as the others who made helpful editorial suggestions.