<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">When working with points, I’ll sometimes make a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">typealias</code> to an integer tuple:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">typealias</span> <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Point</span> = (x: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>, y: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>)
</code></pre>
<p style="margin:0px 0px 1.2em!important">However, if I want to add extended functionality to my <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Point</code> type, I would have to change it to a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">struct</code>, removing the ability to create one on the fly with a tuple.</p>
<p style="margin:0px 0px 1.2em!important">I’m proposing a <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">TupleConvertible</code> protocol that allows initialization from a tuple directly.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-class"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">struct</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">Point</span>: <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">TupleConvertible</span> </span>{

    <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">var</span> x, y: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>

    <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>(x: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>, y: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>) {
        <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">self</span>.x = x
        <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">self</span>.y = y
    }

    <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>(tuple: (x: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>, y: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Int</span>)) {
        <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">self</span>.<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">init</span>(x: tuple.x, y: tuple.y)
    }

}
</code></pre>
<p style="margin:0px 0px 1.2em!important">This would make it very easy to create new <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">Point</code> instances.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> somePoint: <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Point</span> = (<span class="hljs-number" style="color:rgb(0,128,128)">50</span>, <span class="hljs-number" style="color:rgb(0,128,128)">120</span>)
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> otherPoint = <span class="hljs-type" style="color:rgb(68,85,136);font-weight:bold">Point</span>(x: <span class="hljs-number" style="color:rgb(0,128,128)">50</span>, y: <span class="hljs-number" style="color:rgb(0,128,128)">120</span>)
</code></pre>
<div title="MDH:V2hlbiB3b3JraW5nIHdpdGggcG9pbnRzLCBJJ2xsIHNvbWV0aW1lcyBtYWtlIGEgYHR5cGVhbGlh
c2AgdG8gYW4gaW50ZWdlciB0dXBsZTo8ZGl2PmBgYHN3aWZ0PC9kaXY+PGRpdj50eXBlYWxpYXMg
UG9pbnQgPSAoeDogSW50LCB5OiBJbnQpPC9kaXY+PGRpd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