<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">The “Swifty” way of doing such a thing is to have the types you care about conform to a protocol that clearly defines the API you’re trying to expose. For example:<div class=""><br class=""></div><div class="">protocol Fooable {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func doFoo()</div><div class="">}</div><div class=""><br class=""></div><div class="">extension Int: Fooable {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func doFoo() {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>print("I’m an Int")</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div><div class=""><br class=""></div><div class="">extension String: Fooable {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func doFoo() {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>print("I’m a String")</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div><div class=""><br class=""></div><div class="">Now, instead of a disjunctive Int | String union type you can just use Fooable and call doFoo on it when necessary:</div><div class=""><br class=""></div><div class="">func doSomethingWithAFooable(_ foo: Fooable) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>foo.doFoo()</div><div class="">}</div><div class=""><br class=""></div><div class="">doSomethingWithAFooable(0) // prints: I’m an Int</div><div class="">doSomethingWithAFooable("") // prints: I’m a String</div><div 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="">Saagar Jha</div>

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Jan 13, 2018, at 01:45, Daryle Walker via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">From &lt;<a href="https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md#miscellaneous" class="">https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md#miscellaneous</a>&gt;.</div><div class=""><br class=""></div><div class="">Maybe I’m not up on my Type Theory, but why should type constraint disjunctions be banned?</div><br class=""><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">—&nbsp;</div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com&nbsp;</div></div>
</div>
<br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>