<div>I would suggest a keypath using ~ which is concise and clearer to identify.</div><div><br></div><div><span style="color:rgb(34,34,34);font-size:14px;white-space:pre-wrap">        </span><span style="color:rgb(34,34,34);font-size:14px">let myPath = Person~friends[0].name</span><br></div><div><span style="color:rgb(34,34,34);font-size:14px"><br></span></div><div><span style="color:rgb(34,34,34);font-size:14px"><br></span></div><div><br></div><br><br>On Sunday, March 19, 2017, Jonathan Hull via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This looks fantastic!<div><br></div><div>The one worry I would have, as others have brought up, is confusion when there are static properties with the same name.  Maybe we could have a special static property called ‘keyPath’ or ‘path’ that would be reserved, and anything that followed would be a key path.</div><div><br></div><div>So instead of:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>let myPath = Person.friends[0].name</div><div><br></div><div>you would have:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>let myPath = Person.keyPath.friends[0].name</div><div><br></div><div><br></div><div>Or if we want to choose a sentinel, I would nominate ‘$’:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>let myPath = $Person.friends[0].name</div><div><br></div><div>Thanks,</div><div>Jon</div><div><br></div><div><br><div><blockquote type="cite"><div>On Mar 17, 2017, at 10:04 AM, Michael LeHew via swift-evolution &lt;<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;swift-evolution@swift.org&#39;);" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word;line-break:after-white-space"><div dir="auto" style="word-wrap:break-word;line-break:after-white-space">Hi friendly swift-evolution folks,<div><br></div><div>The Foundation and Swift team  would like for you to consider the following proposal:</div><div><br></div><div>Many thanks,</div><div>-Michael</div><div><br></div><div><h1 style="margin:0px 0px 10px;padding:0px;font-size:28px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Smart KeyPaths: Better Key-Value Coding for Swift</h1><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><li style="margin:0px">Proposal: SE-NNNN</li><li style="margin:0px">Authors: <a href="https://github.com/Catfish-Man" style="color:rgb(65,131,196);margin-top:0px" target="_blank">David Smith</a>, <a href="https://github.com/mlehew" style="color:rgb(65,131,196)" target="_blank">Michael LeHew</a>, <a href="https://github.com/jckarter" style="color:rgb(65,131,196)" target="_blank">Joe Groff</a></li><li style="margin:0px">Review Manager: TBD</li><li style="margin:0px">Status: <strong style="margin-top:0px">Awaiting Review</strong></li><li style="margin:0px">Associated PRs:<ul style="margin:0px 0px 15px;padding-left:30px"><li style="margin:0px"><a href="https://github.com/apple/swift-evolution/pull/644" style="color:rgb(65,131,196);margin-top:0px" target="_blank">#644</a></li></ul></li></ul><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Introduction</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">We propose a family of concrete <em>Key Path</em> types that represent uninvoked references to properties that can be composed to form paths through many values and directly get/set their underlying values.</p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Motivation</h2><h4 style="margin:20px 0px 10px;padding:0px;font-size:16px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">We Can Do Better than String</h4><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">On Darwin platforms Swift&#39;s existing <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">#keyPath()</code> syntax provides a convenient way to safely <em>refer</em> to properties. Unfortunately, once validated, the expression becomes a <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">String</code> which has a number of important limitations:</p><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><li style="margin:0px">Loss of type information (requiring awkward <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Any</code> APIs)</li><li style="margin:0px">Unnecessarily slow to parse</li><li style="margin:0px">Only applicable to <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">NSObjects</code></li><li style="margin:0px">Limited to Darwin platforms</li></ul><h4 style="margin:20px 0px 10px;padding:0px;font-size:16px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Use/Mention Distinctions</h4><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">While methods can be referred to without invoking them (<code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">let x = foo.bar</code> instead of  <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">let x = foo.bar()</code>), this is not currently possible for properties and subscripts.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Making indirect references to a properties&#39; concrete types also lets us expose metadata about the property, and in the future additional behaviors.</p><h4 style="margin:20px 0px 10px;padding:0px;font-size:16px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">More Expressive KeyPaths</h4><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">We would also like to support being able to use <em>Key Paths</em> to access into collections, which is not currently possible.</p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Proposed solution</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">We propose introducing a new expression akin to <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Type.method</code>, but for properties and subscripts. These property reference expressions produce <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPath</code> objects, rather than <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Strings</code>. <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPaths</code> are a family of generic classes <em>(structs and protocols here would be ideal, but requires generalized existentials)</em> which encapsulate a property reference or chain of property references, including the type, mutability, property name(s), and ability to set/get values.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Here&#39;s a sample of it in use:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">struct</span> <span style="color:rgb(102,153,0)">Person</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:rgb(0,119,170)">var</span> name<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">String</span>
    <span style="color:rgb(0,119,170)">var</span> friends<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(153,153,153)">[</span><span style="color:rgb(102,153,0)">Person</span><span style="color:rgb(153,153,153)">]</span>
    <span style="color:rgb(0,119,170)">var</span> bestFriend<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">Person</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span>
<span style="color:rgb(153,153,153)">}</span>

<span style="color:rgb(0,119,170)">var</span> han <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span style="color:rgb(221,74,104)">Person</span><span style="color:rgb(153,153,153)">(</span>name<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">&quot;Han Solo&quot;</span><span style="color:rgb(153,153,153)">,</span> friends<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,153,153)">]</span><span style="color:rgb(153,153,153)">)</span>
<span style="color:rgb(0,119,170)">var</span> luke <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span style="color:rgb(221,74,104)">Person</span><span style="color:rgb(153,153,153)">(</span>name<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">&quot;Luke Skywalker&quot;</span><span style="color:rgb(153,153,153)">,</span> friends<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(153,153,153)">[</span>han<span style="color:rgb(153,153,153)">]</span><span style="color:rgb(153,153,153)">)</span>

<span style="color:rgb(0,119,170)">let</span> firstFriendsNameKeyPath <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span style="color:rgb(102,153,0)">Person</span><span style="color:rgb(153,153,153)">.</span>friends<span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,0,85)">0</span><span style="color:rgb(153,153,153)">]</span><span style="color:rgb(153,153,153)">.</span>name

<span style="color:rgb(0,119,170)">let</span> firstFriend <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> luke<span style="color:rgb(153,153,153)">[</span>path<span style="color:rgb(153,153,153)">]</span> <span style="color:slategray">// han</span>

<span style="color:slategray">// or equivalently, with type inferred from context</span>
<span style="color:rgb(0,119,170)">let</span> firstFriendName <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> luke<span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,153,153)">.</span>friends<span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,0,85)">0</span><span style="color:rgb(153,153,153)">]</span><span style="color:rgb(153,153,153)">.</span>name<span style="color:rgb(153,153,153)">]</span>

<span style="color:slategray">// rename Luke&#39;s first friend</span>
luke<span style="color:rgb(153,153,153)">[</span>firstFriendsNameKeyPath<span style="color:rgb(153,153,153)">]</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span style="color:rgb(102,153,0)">&quot;A Disreputable Smuggler&quot;</span>

<span style="color:rgb(0,119,170)">let</span> bestFriendsName <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> luke<span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,153,153)">.</span>bestFriend<span style="color:rgb(153,153,153)">]</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span><span style="color:rgb(153,153,153)">.</span>name  <span style="color:slategray">// nil, if he is the last jedi</span></code></pre></div><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Detailed design</h2><h3 style="margin:20px 0px 10px;padding:0px;font-size:18px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Core KeyPath Types</h3><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPaths</code> are a hierarchy of progressively more specific classes, based on whether we have prior knowledge of the path through the object graph we wish to traverse. </p><h5 style="margin:20px 0px 10px;padding:0px;font-size:14px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Unknown Path / Unknown Root Type</h5><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">AnyKeyPath</code> is fully type-erased, referring to &#39;any route&#39; through an object/value graph for &#39;any root&#39;. Because of type-erasure many operations can fail at runtime and are thus nillable. </p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">class</span> <span>AnyKeyPath</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">CustomDebugStringConvertible</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Hashable</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:slategray">// MARK - Composition</span>
    <span style="color:slategray">// Returns nil if path.rootType != self.valueType</span>
    <span style="color:rgb(0,119,170)">func</span> <span style="color:rgb(221,74,104)">appending</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span>
    
    <span style="color:slategray">// MARK - Runtime Information        </span>
    <span style="color:rgb(0,119,170)">class</span> <span>var</span> rootType<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">Any</span><span style="color:rgb(153,153,153)">.</span><span style="color:rgb(0,119,170)">Type</span>
    <span style="color:rgb(0,119,170)">class</span> <span>var</span> valueType<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">Any</span><span style="color:rgb(153,153,153)">.</span><span style="color:rgb(0,119,170)">Type</span>
    
    <span style="color:rgb(0,119,170)">static</span> <span style="color:rgb(0,119,170)">func</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">==</span> <span style="color:rgb(153,153,153)">(</span>lhs<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(153,153,153)">,</span> rhs<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">Bool</span>
    <span style="color:rgb(0,119,170)">var</span> hashValue<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">Int</span>
<span style="color:rgb(153,153,153)">}</span></code></pre></div><h5 style="margin:20px 0px 10px;padding:0px;font-size:14px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Unknown Path / Known Root Type</h5><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">If we know a little more type information (what kind of thing the key path is relative to), then we can use <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">PartialKeyPath &lt;Root&gt;</code>, which refers to an &#39;any route&#39; from a known root:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">class</span> <span>PartialKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:slategray">// MARK - Composition</span>
    <span style="color:slategray">// Returns nil if Value != self.valueType</span>
    <span style="color:rgb(0,119,170)">func</span> <span style="color:rgb(221,74,104)">appending</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">PartialKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">ReferenceKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">ReferenceKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span>
<span style="color:rgb(153,153,153)">}</span></code></pre></div><h5 style="margin:20px 0px 10px;padding:0px;font-size:14px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Known Path / Known Root Type</h5><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">When we know both what the path is relative to and what it refers to, we can use <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPath</code>. Thanks to the knowledge of the Root and Value types, all of the failable operations lose their Optional. </p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">public</span> <span style="color:rgb(0,119,170)">class</span> <span>KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">PartialKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:slategray">// MARK - Composition</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(0,119,170)">Self</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">ReferenceWritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)"><wbr>,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">ReferenceWritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span>
<span style="color:rgb(153,153,153)">}</span></code></pre></div><h5 style="margin:20px 0px 10px;padding:0px;font-size:14px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Value/Reference Mutation Semantics Mutation</h5><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Finally, we have a pair of subclasses encapsulating value/reference mutation semantics. These have to be distinct because mutating a copy of a value is not very useful, so we need to mutate an inout value.</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">class</span> <span>WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:slategray">// MARK - Composition</span>
    <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>p<wbr>ath<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span>
<span style="color:rgb(153,153,153)">}</span>

<span style="color:rgb(0,119,170)">class</span> <span>ReferenceWritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:rgb(0,119,170)">override</span> <span style="color:rgb(0,119,170)">func</span> appending<span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>p<wbr>ath<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">ReferenceWritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">AppendedPathValue</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span>
<span style="color:rgb(153,153,153)">}</span></code></pre></div><h3 style="margin:20px 0px 10px;padding:0px;font-size:18px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Access and Mutation Through KeyPaths</h3><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">To get or set values for a given root and key path we effectively add the following subscripts to all Swift types. </p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span style="color:rgb(0,119,170)">extension</span> <span style="color:rgb(102,153,0)">Any</span> <span style="color:rgb(153,153,153)">{</span>
    <span style="color:rgb(0,119,170)">subscript</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">AnyKeyPath</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">Any</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span> <span style="color:rgb(153,153,153)">{</span> <span style="color:rgb(0,119,170)">get</span> <span style="color:rgb(153,153,153)">}</span>
    <span style="color:rgb(0,119,170)">subscript</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(0,119,170)">Self</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">PartialKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">Any</span> <span style="color:rgb(153,153,153)">{</span> <span style="color:rgb(0,119,170)">get</span> <span style="color:rgb(153,153,153)">}</span>
    <span style="color:rgb(0,119,170)">subscript</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(0,119,170)">Self</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">KeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">Value</span> <span style="color:rgb(153,153,153)">{</span> <span style="color:rgb(0,119,170)">get</span> <span style="color:rgb(153,153,153)">}</span>
    <span style="color:rgb(0,119,170)">subscript</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(0,119,170)">Self</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">(</span>path<span style="color:rgb(153,153,153)">:</span> <span style="color:rgb(102,153,0)">WritableKeyPath</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&lt;</span><span style="color:rgb(102,153,0)">Root</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(102,153,0)">Value</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span><span style="color:rgb(153,153,153)">)</span> <span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">&gt;</span> <span style="color:rgb(102,153,0)">Value</span> <span style="color:rgb(153,153,153)">{</span> <span style="color:rgb(0,119,170)">set</span><span style="color:rgb(153,153,153)">,</span> <span style="color:rgb(0,119,170)">get</span> <span style="color:rgb(153,153,153)">}</span>
<span style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">This allows for code like</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div><div style="background-color:rgb(207,207,207);display:inline-block;width:auto;height:auto;font-size:0.9em;border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:5px;padding:0px 0.5em">Swift</div></div><pre style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;white-space:pre-wrap;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal"><code style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,&#39;Andale Mono&#39;,&#39;Ubuntu Mono&#39;,monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5">person<span style="color:rgb(153,153,153)">[</span><span style="color:rgb(153,153,153)">.</span>name<span style="color:rgb(153,153,153)">]</span> <span style="color:slategray">// Self.type is inferred</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">which is both appealingly readable, and doesn&#39;t require read-modify-write copies (subscripts access <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">self</code> inout). Conflicts with existing subscripts are avoided by using generic subscripts to specifically only accept key paths with a <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Root</code> of the type in question.</p><h3 style="margin:20px 0px 10px;padding:0px;font-size:18px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Referencing Key Paths</h3><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Forming a <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPath</code> borrows from the same syntax used to reference methods and initializers,<code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Type.<wbr>instanceMethod</code> only now working for properties and collections. Optionals are handled via optional-chaining. Multiply dotted expressions are allowed as well, and work just as if they were composed via the <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">appending</code> methods on <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPath</code>.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">There is no change or interaction with the #keyPath() syntax introduced in Swift 3. </p><h3 style="margin:20px 0px 10px;padding:0px;font-size:18px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Performance</h3><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">The performance of interacting with a property via <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">KeyPaths</code> should be close to the cost of calling the property directly.</p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Source compatibility</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">This change is additive and there should no affect on existing source. </p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Effect on ABI stability</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">This feature adds the following requirements to ABI stability: </p><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><li style="margin:0px">mechanism to access key paths of public properties</li></ul><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">We think a protocol-based design would be preferable once the language has sufficient support for generalized existentials to make that ergonomic. By keeping the class hierarchy closed and the concrete implementations private to the implementation it should be tractable to provide compatibility with an open protocol-based design in the future.</p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Effect on API resilience</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">This should not significantly impact API resilience, as it merely provides a new mechanism for operating on existing APIs.</p><h2 style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">Alternatives considered</h2><h4 style="margin:20px 0px 10px;padding:0px;font-size:16px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)">More Features</h4><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Various drafts of this proposal have included additional features (decomposable key paths, prefix comparisons, support for custom <code style="margin:0px 2px;padding:0px 5px;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px"></code></p></div></div></div></div></blockquote></div></div></div></blockquote>