# Allow key paths to reference unapplied instance methods

**URL:** <https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582>\
**Category:** Pitches\
**Created:** [April 21, 2020, 9:18pm UTC](https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582 "2020-04-21T21:18:45Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Paul\_Cantrell](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/paul_cantrell/32/16764_2.png) [@Paul\_Cantrell](https://forums.swift.org/u/Paul_Cantrell)\
**Post date:** [April 23, 2020, 12:17am UTC](https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582/15 "2020-04-23T00:17:31Z")

</div>

> [@anandabits](#):
>
> In that section you're asking questions about the `KeyPath` type. I'm only talking about using key path syntax to access unbound methods as functions

That section does cover both, though perhaps so obliquely it was easy to miss. In fact it directly mentions [your idea](https://forums.swift.org/t/why-can-t-key-paths-refer-to-instance-methods/35315/26) of adding an `inout` param for mutating methods:

> Key paths for mutating methods might induce an `inout` param for self:
> 
> ```swift
> let appender: (inout Array<Int>, Int) -> Void = \Array.append
> appender(primes, 7)
> 
> ```

…and it draws exactly the contrast you’re talking about:

> …but that idea only makes sense when using key path literals as a convenience to form closures; it quickly breaks down when using actual key path values as subscripts:
> 
> ```swift
> var mersennes = [0, 1, 3]
> primes[keyPath: \.append](mersennes, 7) // Which is mutated: mersennes or primes?
> 
> ```

…arguing that we’re better off considering mutating methods as a separate design unit (which I’m all in favor of doing, should this proposal pass):

> This line of reasoning suggests that mutating methods are best left for a follow-up proposal:
> 
> - If they are in fact limited to key path _literals_ converted to closures, then they are both outside the scope of this proposal and not in conflict with it.
> - If we seek a broader solution, it would need to be consistent with unbound methods as well, and thus (as in the previous section) this proposal is only uniformly respecting an existing problem, not introducing a new one.

(And just to be crystal clear: I'm all for another proposal to meet the need you're talking about; it seems compelling.)

---

_[View the full topic](https://forums.swift.org/t/allow-key-paths-to-reference-unapplied-instance-methods/35582)._
