<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 3:05 PM, Charles Srstka <span dir="ltr">&lt;<a href="mailto:cocoadev@charlessoft.com" target="_blank">cocoadev@charlessoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><blockquote type="cite">On Aug 15, 2016, at 2:27 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote><div><blockquote type="cite"><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">`let value = (x == nil) ? nil : foo.bar(x: x)` isn&#39;t so bad, is it? You could even write a custom operator to sugar it.</span></div></blockquote></div><br></span><div>It’s distasteful, due to the need to use the force-unwrap operator. In cases like this, I usually end up writing:</div><div><br></div><div>let value: Foo? = nil</div><span class=""><div><br></div><div>if let x = x {</div></span><div><span style="white-space:pre-wrap">        </span>value = foo.bar(x: x)</div><div>} else {</div><div><span style="white-space:pre-wrap">        </span>value = nil</div><div>}</div><div><br></div><div>or:</div><div><br></div><div>let value: Foo? = {</div><span class=""><div><span style="white-space:pre-wrap">        </span>if let x = x {</div></span><div><span style="white-space:pre-wrap">                </span>return foo.bar(x: x)</div><div><span style="white-space:pre-wrap">        </span>} else {</div><div><span style="white-space:pre-wrap">                </span>return nil</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}()</div><div><br></div><div>Both of which are unwieldy, but necessary to avoid the use of !.</div></div></blockquote><div><br></div><div>You are arguing that the force unwrap operator ! is, per se, distasteful?</div><div> </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"><div><br></div><div>I wouldn’t mind something like an overload on the ternary operator:</div><div><br></div><div>let value = x? ? foo.bar(x: x) : nil</div><div><br></div><div>in which a ? after the ternary condition indicates that it is an optional to be unwrapped for the positive condition.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Charles</div><div><br></div></font></span></div></blockquote></div><br></div></div>