<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 class="">That’s a really interesting idea.</div><div class="">There’s potential to add parameter names. Ideally the second parameter name would be ‘else’, but that’s not really workable.&nbsp;</div><div class=""><br class=""></div><div class=""><div class="">func when&lt;T&gt;(fn: Bool, @autoclosure then: () -&gt; T, @autoclosure or: () -&gt; T) -&gt; T {</div><div class="">&nbsp; if fn { return then() }</div><div class="">&nbsp; return or()</div><div class="">}</div><div class=""><br class=""></div><div class="">let x = when(true, then: 0, or: 1)</div><div class=""><br class=""></div><div class="">Nested version might be a bit scary though ; )</div><div class=""><br class=""></div><div class="">let nested = when(false, then: 0, or: when(false, then: 2, or: when(true, then: 3, or: 4)))</div></div><div class=""><br class=""></div><div class="">Al</div><br class=""><div><blockquote type="cite" class=""><div class="">On 14 Dec 2015, at 18:38, David Owens II 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=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;">Thanks for the updated proposals; they are much easier to go through then the vast number of mails on this thread. I’ve tried to follow this thread as best as possible, so please forgive me if this has been addressed but I couldn’t find it.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;">Can you add to the proposal why a function cannot be added for tertiary expressions (under “Alternates Considered”):</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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; margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="Menlo" class="">func&nbsp;either&lt;T&gt;(@autoclosure&nbsp;fn: () -&gt;&nbsp;Bool,&nbsp;@autoclosure&nbsp;_&nbsp;left: () -&gt;&nbsp;T,&nbsp;@autoclosure&nbsp;_&nbsp;right: () -&gt;&nbsp;T) -&gt;&nbsp;T&nbsp;{</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;&nbsp;if&nbsp;fn() {&nbsp;return&nbsp;left() }</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;&nbsp;return&nbsp;right()</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let&nbsp;x =&nbsp;true&nbsp;?&nbsp;0&nbsp;:&nbsp;1</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let&nbsp;y =&nbsp;either(true,&nbsp;0,&nbsp;1)</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let&nbsp;f1: () -&gt;&nbsp;Int&nbsp;= {&nbsp;print("f1");&nbsp;return&nbsp;0&nbsp;}</font></div><div class=""><font face="Menlo" class="">let&nbsp;f2: () -&gt;&nbsp;Int&nbsp;= {&nbsp;print("f2");&nbsp;return&nbsp;2&nbsp;}</font></div><div class=""><font face="Menlo" class="">let&nbsp;z =&nbsp;either(true,&nbsp;f1(),&nbsp;f2())</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">let nested =&nbsp;either(false,&nbsp;0,&nbsp;either(false,&nbsp;2,&nbsp;either(true,&nbsp;3,&nbsp;4)))<br class=""><br class=""></font></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;">This isn’t a full replacement for if-statements as expressions, but doesn’t it satisfy the tertiary requirements, at least in the most common of cases? The fallback is to use if-else if side-effects are something that is desired?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;">The name for the function could be better, but the point is to remove it from the parsing structure all together. Or is that something you find valuable?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;">-David</div></div></blockquote></div><br class=""></body></html>