<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=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class="">Le 17 sept. 2017 à 18:00, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">I found that for Sequence, but Sequence is far from the only protocol with default implementations, and not all of them have maintainers willing to write and update documentation to the degree that Apple will.</div></div></blockquote><br class=""></div><div class=""><div class="">How I do it is like this:</div><div class=""><br class=""></div><div class="">1. Make a dummy struct (or class) that claim conformance to a protocol:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; color: rgb(195, 89, 0); background-color: rgb(255, 252, 249);"><span class="" style="color: rgb(54, 86, 138);">struct</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;Z:&nbsp;</span>Collection<span class="" style="color: rgb(0, 0, 0);">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);">}</div></div><div class=""><br class=""></div><div class="">2. Compiling, then deciphering the errors tells me that type deduction doesn't work for associated type `Index` because there is no subscript. So I add one:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; color: rgb(195, 89, 0); background-color: rgb(255, 252, 249);"><span class="" style="color: rgb(54, 86, 138);">struct</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;Z:&nbsp;</span>Collection<span class="" style="color: rgb(0, 0, 0);">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">subscript</span>&nbsp;(index:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>) -&gt;&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">                </span><span class="" style="color: rgb(54, 86, 138);">get</span>&nbsp;{&nbsp;<span class="" style="color: rgb(54, 86, 138);">return</span>&nbsp;index }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);">}</div></div><div class=""><br class=""></div><div class="">3. Compiling again, I now get a suggestion (fixit) telling me to add `startIndex` and `endIndex`. I add the suggested code:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; color: rgb(195, 89, 0); background-color: rgb(255, 252, 249);"><span class="" style="color: rgb(54, 86, 138);">struct</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;Z:&nbsp;</span>Collection<span class="" style="color: rgb(0, 0, 0);">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">var</span>&nbsp;startIndex:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span></div><div class="" style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 249); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">var</span>&nbsp;endIndex:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span></div><div class="" style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 249); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">subscript</span>&nbsp;(index:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>) -&gt;&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">                </span><span class="" style="color: rgb(54, 86, 138);">get</span>&nbsp;{&nbsp;<span class="" style="color: rgb(54, 86, 138);">return</span>&nbsp;index }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);">}</div></div><div class=""><br class=""></div><div class="">4. Compiling again, I get another suggestion (fixit) telling me I'm missing `index(after:)`. I add it and write an implementation inside the braces. And here I am:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; color: rgb(195, 89, 0); background-color: rgb(255, 252, 249);"><span class="" style="color: rgb(54, 86, 138);">struct</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;Z:&nbsp;</span>Collection<span class="" style="color: rgb(0, 0, 0);">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">func</span>&nbsp;index(after i:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>) -&gt;&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">                </span><span class="" style="color: rgb(54, 86, 138);">return</span>&nbsp;i +&nbsp;<span class="" style="color: rgb(54, 86, 138);">1</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 249); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">var</span>&nbsp;startIndex:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span></div><div class="" style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 249); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">var</span>&nbsp;endIndex:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span></div><div class="" style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 252, 249); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(54, 86, 138);">subscript</span>&nbsp;(index:&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>) -&gt;&nbsp;<span class="" style="color: rgb(195, 89, 0);">Int</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">                </span><span class="" style="color: rgb(54, 86, 138);">get</span>&nbsp;{&nbsp;<span class="" style="color: rgb(54, 86, 138);">return</span>&nbsp;index }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Mono'; background-color: rgb(255, 252, 249);">}</div></div><div class=""><br class=""></div><div class="">5. And now it compiles. Hurray!</div><div class=""><br class=""></div><div class="">I made a collection type and did not have to read any documentation at all. The hardest step is the first one where you have to figure out how to make deduction work for the associated types based on the error messages.</div><div class=""><br class=""></div></div><br class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="" style="font-family: Helvetica; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; text-align: -webkit-auto; border-spacing: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; text-align: -webkit-auto; border-spacing: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">--&nbsp;<br class="">Michel Fortin</div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="" style="text-align: -webkit-auto;"><a href="https://michelf.ca/" class="">https://michelf.ca</a></span></div><div class=""><br class=""></div></span></div></span></div></span></div></div></div></div></div></div></div><br class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">--&nbsp;<br class="">Michel Fortin</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="text-align: -webkit-auto;" class=""><a href="https://michelf.ca" class="">https://michelf.ca</a></span></div></span></div></span></div></span></div></div></div></div>
</div>
<br class=""></body></html>