<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>The ?? operator is overloaded to take an optional as the second parameter already. So you can simply chain the ?? over and over with the the last being non optional, which will be the value of all others fail.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">With that in mind, a <span style="background-color: rgba(255, 255, 255, 0);">firstNonOptional function wouldn't be hard to implement.</span></div><div id="AppleMailSignature"><br>Sent from my iPad</div><div><br>On Jan 29, 2016, at 9:25 AM, Ross O'Brien via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">What about it?<div><br></div><div>"x ?? false" is simple. If x isn't nil, return x; if x is nil, return false.</div><div>"x?.isEmpty ?? false" again is already readable; if x isn't nil, return x.isEmpty; if x is nil, return false.</div><div><br></div><div><div>"Bool(x?.isEmpty)" seems be suggesting that the Bool type has a failable initialiser "init?(_: Bool?)". If x is nil, x.isEmpty would be nil, so the resulting Bool would be nil, not false - this code returns a Bool?, which you already had.</div></div><div><br></div><div>"??(false, x?.isEmpty)" ... uses an operator as an identifier, for a start. At best I'd try to interpret this like reduce - take a collection or variadic list of optionals, return the value of the first non-nil else return the "default". Except I'd still put the default at the end, because I can't think why it would be at the start.</div><div><br></div><div>So, if the given problem is taking the nil-coalescing and putting it up front, perhaps there should be a global generic function:</div><div><br></div><div>func firstNonOptional&lt;T&gt;(possibles:T?..., failsafe:T) -&gt; T</div><div>{</div><div>&nbsp; &nbsp; return possibles.reduce(nil, combine:{ $0 ?? $1 }) ?? failsafe</div><div>}</div><div><br></div><div>&nbsp;<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 29, 2016 at 1:48 PM, Amir Michail via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</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"><br><div><blockquote type="cite"><div>On Jan 29, 2016, at 8:42 AM, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">still much worse.<div><br></div></div></div></blockquote><div><br></div><div>What about: Bool(x?.isEmpty) // nil and false =&gt; false</div><div><div class="h5"><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br><div><blockquote type="cite"><div>On 2016-01-29, at 20:41:06, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jan 29, 2016, at 5:03 AM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>&gt; wrote:</div><br><div><div><div>I agree with Erica. The ?? operator is very readable IMO.<br></div><div><br></div><div>Furthermore x?(false).isEmpty looks like it would evaluate false.isEmpty when x is nil which is certainly not what is intended.<br></div></div></div></blockquote><div><br></div><div>What about this then: ??(false, x?.isEmpty)</div><br><blockquote type="cite"><div><div><div>In addition it would not be clear which default should be used in case of multiple optional chainings happening, i.e. what should be the result of person?(false).address?.(true).isEmpty<br></div><div><br></div><div>-Thorsten</div><div><br></div><div><br>Am 26. Januar 2016 um 03:29 schrieb Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br><div><blockquote type="cite"><div><div><span>Not loving this. I'm quite happy with ??-coalescing and don't see<br>a compelling reason it needs to be "cleaner". I find your suggested<br>enhancement less readable. Looks like an optional chaining across <br>a function.<br><br>-- E<br><br><blockquote type="cite">On Jan 25, 2016, at 7:03 PM, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Examples:</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">* instead of x ?? false, you would have x?(false)</blockquote><blockquote type="cite">* instead of x?.isEmpty ?? false, you would have x?(false).isEmpty</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I think this change would result in cleaner looking code.</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________</blockquote><blockquote type="cite">swift-evolution mailing list</blockquote><blockquote type="cite"><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br></blockquote><blockquote type="cite"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></blockquote><br>_______________________________________________<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></span></div></div></blockquote></div></div></div></div></blockquote></div><br></div>_______________________________________________<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><br></div></div></div></blockquote></div></div></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>