[Accepted] SE-0249: Key Paths Expressions as Functions

The review of SE-0249 has concluded and the proposal has been accpted:

16 Likes

Addendum: we've added a section to this proposal to clarify that the key-path expression is evaluated immediately and exactly once. This differs from the informal description of being equivalent to { $0[keyPath: <PATH>] } in the case where there are expressions embedded within the key-path expression, e.g. \Person.children[i]: in the closure, the expression i is of course evaluated anew every time the closure is called, whereas in an ordinary key-path literal i is evaluated immediately and then that specific value is captured in the KeyPath value.

The Core Team feels that these are the "obviously correct" semantics for this feature, the semantics which most people would expect from it, and so there is no need for further review on this topic. These semantics are also consistent with the possible future generalization of SE-0249 to allow arbitrary key-path expressions to be treated as functions, rather than only literals.

Thanks to @stephencelis and @beccadax for taking the lead on fixing the wording here.

5 Likes

Hi John, one quick question.

Could this create any issues if we would re-evaluate SE-0042 and also use a key-path literal to generate a closure?

Related topic:

No, I don't think we would expect SE-0042 to change dynamic semantics, just type-system behavior.