[swift-evolution] Smart KeyPaths
Douglas Gregor
dgregor at apple.com
Wed Mar 29 21:22:43 CDT 2017
Sent from my iPhone
> On Mar 29, 2017, at 6:32 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>
>>> On Mar 29, 2017, at 6:21 PM, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> I would love it if we found a way to retain something as concise as that shorthand. I'm working on a library where users will specify a collection of key paths pairs. This shorthand would be a very nice piece of sugar making the code expressing these collections (usually literals) quite a bit more readable.
>>
>> +1 for this. I think it will be somewhat common to pass around arrays of these things, and a shorthand syntax of some sort would make that nicer. That said, I don’t want to slow down the proposal, since I will be using this feature the very second it becomes available.
>
> Agreed.
>
> One more thought on this: I don't think anyone really likes the #keyPath(Type, .key1.key2)` syntax; it's just the best we've come up with. If the syntax were instead this:
>
> #keyPath(Type).key1.key2
>
> I think that would look cleaner and avoid drawing distinctions based on subtle punctuation differences. I don't think it would clash with old-style key paths since you can't have a key path to a type name anyway. And support for the leading-dot syntax would fall out of it quite naturally.
To me, this reads as if you're accessing ".key1.key2" on the KeyPath instance, not forming a keypath. I think the whole "path" should say in the parens.
- Doug
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170329/58a893f7/attachment.html>
More information about the swift-evolution
mailing list