<p dir="ltr">I was thinking it could work for variables that are already tuples but then that goes against Swift&#39;s strict typing. So really it should only be for tuple literals.<br>
</p>
<br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 6, 2015, 7:01 PM Stephen Celis &lt;<a href="mailto:stephen.celis@gmail.com">stephen.celis@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Do you mean a TupleLiteralConvertible? I’m also in favor of a ClosureLiteralConvertible (or FunctionLiteralConvertible).<div><br></div><div>Stephen<br><div><br><div><blockquote type="cite"></blockquote></div></div></div></div><div style="word-wrap:break-word"><div><div><div><blockquote type="cite"><div>On Dec 6, 2015, at 6:40 PM, Nikolai Vazquez via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></blockquote></div></div></div></div><div style="word-wrap:break-word"><div><div><div><blockquote type="cite"><div><div dir="ltr"><div><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 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-wrap;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 style="color:rgb(51,51,51);font-weight:bold">typealias</span> <span style="color:rgb(68,85,136);font-weight:bold">Point</span> = (x: <span style="color:rgb(68,85,136);font-weight:bold">Int</span>, y: <span 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 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-wrap;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><span style="color:rgb(51,51,51);font-weight:bold">struct</span> <span style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">Point</span>: <span style="color:rgb(153,0,0);font-weight:bold;color:rgb(68,85,136);font-weight:bold">TupleConvertible</span> </span>{

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

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

    <span style="color:rgb(51,51,51);font-weight:bold">init</span>(tuple: (x: <span style="color:rgb(68,85,136);font-weight:bold">Int</span>, y: <span style="color:rgb(68,85,136);font-weight:bold">Int</span>)) {
        <span style="color:rgb(51,51,51);font-weight:bold">self</span>.<span 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 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-wrap;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 style="color:rgb(51,51,51);font-weight:bold">let</span> somePoint: <span style="color:rgb(68,85,136);font-weight:bold">Point</span> = (<span style="color:rgb(0,128,128)">50</span>, <span style="color:rgb(0,128,128)">120</span>)
<span style="color:rgb(51,51,51);font-weight:bold">let</span> otherPoint = <span style="color:rgb(68,85,136);font-weight:bold">Point</span>(x: <span style="color:rgb(0,128,128)">50</span>, y: <span style="color:rgb(0,128,128)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ZGl2PiZuYnNwOyAmbmJzcDsgfTwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+
Jm5ic3A7ICZuYnNwOyBpbml0KHR1cGxlOiAoeDogSW50LCB5OiBJbnQpKSB7PC9kaXY+PGRpdj4m
bmJzcDsgJm5ic3A7ICZuYnNwOyAmbmJzcDsgc2VsZi5pbml0KHg6IHR1cGxlLngsIHk6IHR1cGxl
LnkpPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IH08L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2Pn08
L2Rpdj48ZGl2PmBgYDwvZGl2PjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+VGhpcyB3b3VsZCBt
YWtlIGl0IHZlcnkgZWFzeSB0byBjcmVhdGUgbmV3IGBQb2ludGAgaW5zdGFuY2VzLjwvZGl2Pjxk
aXY+PGRpdj5gYGBzd2lmdDwvZGl2PjxkaXY+bGV0IHNvbWVQb2ludDogUG9pbnQgPSAoNTAsIDEy
MCk8L2Rpdj48ZGl2PmxldCBvdGhlclBvaW50ID0gUG9pbnQoeDogNTAsIHk6IDEyMCk8L2Rpdj48
ZGl2PmBgYDwvZGl2PjwvZGl2PjxkaXY+PGJyPjwvZGl2Pg==" style="min-height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div>
</div></blockquote></div></div></div></div><div style="word-wrap:break-word"><div><div><div><blockquote type="cite"><div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=5xu02FVv-2BCbxTLHpBsC0RVeXVC5uCln3pUIIeLTlIi3PNiwjZYG5DrLQWjxWyWV-2BHZxHS9coVxT4qg5XZrpnNkEtnUT1mw0mvnRMOOTtSkNEyelVeO8g4QkcRBcH2SEIr8NkH1VtgOTh-2FfPB3JM6WVYR-2Fbw56PRxDfLy6N0w7-2BAlxHGRf1GxjRTWsa8xw-2Fb4onLWQZ7E-2BvKGlf8eEaeNItqmQ6kz-2BonpL9JbecuUaQ0-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></div></div></blockquote></div>