<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 7, 2016, at 9:34 PM, Les Pruszynski via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This is my first post on this list so please bear with me.<div class=""><br class=""></div><div class="">I very much like this proposal but what bothers me is this doubling of valueForKeyPath(#keyPath(xxx) in the signature of the function.</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class="">chris<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>valueForKeyPath(#keyPath(Person<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>bestFriend<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>lastName)) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// => Groff</span>
chris<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>valueForKeyPath(#keyPath(Person<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>friends<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>firstName)) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// => ["Joe", "Douglas"]</span></pre><div class=""><br class=""></div></div><div class="">I’m not sure whether the form below is actually possible. For me it reads more naturally and is more consistent with “Modern Swift” as far as I know.</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class="">chris<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>valueFor(#keyPath(Person<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>friends<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>firstName)) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// => ["Joe", "Douglas”]</span></pre><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">or maybe</span></pre><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">chris<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>valueOf(#keyPath(Person<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>friends<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>firstName)) // => ["Joe", "Douglas”]</span></pre></div><div class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><br class=""></span></div></div></div></blockquote><br class=""></div><div>If key paths were some stronger type (as Brent is suggesting), we could do this. However, because key paths are just Strings, we need to <a href="https://swift.org/documentation/api-design-guidelines/#promote-clear-usage" class="">compensate for weak type information</a>, so valueForKeyPath should retain it’s currently name despite the redundancy in many use sites with #keyPath.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""></body></html>