<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 9:25 AM, Ross O'Brien <<a href="mailto:narrativium+swift@gmail.com" class="">narrativium+swift@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">What about it?<div class=""><br class=""></div><div class="">"x ?? false" is simple. If x isn't nil, return x; if x is nil, return false.</div><div class="">"x?.isEmpty ?? false" again is already readable; if x isn't nil, return x.isEmpty; if x is nil, return false.</div><div class=""><br class=""></div><div class=""><div class="">"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 class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>How about this:</div><div><br class=""></div><div>if? !x?.isEmpty { … } // if? nil { … } = if false { … }</div><div>while? !x?.isEmpty { … }</div><div>etc.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">"??(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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">func firstNonOptional<T>(possibles:T?..., failsafe:T) -> T</div><div class="">{</div><div class=""> return possibles.reduce(nil, combine:{ $0 ?? $1 }) ?? failsafe</div><div class="">}</div><div class=""><br class=""></div><div class=""> <br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Jan 29, 2016 at 1:48 PM, Amir Michail via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 8:42 AM, Craig Cruden <<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">still much worse.<div class=""><br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">What about: Bool(x?.isEmpty) // nil and false => false</div><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-29, at 20:41:06, Amir Michail via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 5:03 AM, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" target="_blank" class="">tseitz42@icloud.com</a>> wrote:</div><br class=""><div class=""><div class=""><div class="">I agree with Erica. The ?? operator is very readable IMO.<br class=""></div><div class=""><br class=""></div><div class="">Furthermore x?(false).isEmpty looks like it would evaluate false.isEmpty when x is nil which is certainly not what is intended.<br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">What about this then: ??(false, x?.isEmpty)</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="">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 class=""></div><div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class=""></div><div class=""><br class="">Am 26. Januar 2016 um 03:29 schrieb Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>>:<br class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class=""><span class="">Not loving this. I'm quite happy with ??-coalescing and don't see<br class="">a compelling reason it needs to be "cleaner". I find your suggested<br class="">enhancement less readable. Looks like an optional chaining across <br class="">a function.<br class=""><br class="">-- E<br class=""><br class=""><blockquote type="cite" class="">On Jan 25, 2016, at 7:03 PM, Amir Michail via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class="">Examples:</blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class="">* instead of x ?? false, you would have x?(false)</blockquote><blockquote type="cite" class="">* instead of x?.isEmpty ?? false, you would have x?(false).isEmpty</blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class="">I think this change would result in cleaner looking code.</blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class="">_______________________________________________</blockquote><blockquote type="cite" class="">swift-evolution mailing list</blockquote><blockquote type="cite" class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""></blockquote><blockquote type="cite" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div></div></div><br class=""></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>