<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="">It’s curious that your example won’t compile (didn’t when I tried it in a Playground), however the following does:</div><div class=""><br class=""></div><div class=""><div class="">let ps = peeps.filter { $0.pet.map { pet in pet.age < 6 } ?? false }</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">My perspective is still that the issue isn’t with Optionals being comparable, but in certain edge cases the auto wrapping of non Optionals is what causes the confusion, as it’s not obvious that the comparison is between Optionals.</div><div class=""><br class=""></div><div class="">Regarding the default semantics, I’d say the semantics of Optional comparison is pretty reasonable and fits with:</div><div class=""><br class=""></div><div class=""><div class="">"" < "abc" == true</div><div class="">[] < [1,2,3] == true</div><div class="">.None < .Some(0) == true</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Al</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 9 Dec 2015, at 17:44, <a href="mailto:thorsten@portableinnovations.de" class="">thorsten@portableinnovations.de</a> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class="">That's why I would prefer that optionals are not comparable by default.</div><div class=""><br class=""></div><div class="">Then I would simply have to write</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">let ps = peeps.filter { $0.pet?.age.map { age in age < 6 } ?? false }</span></font></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></font></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">making the intended semantics explicit, which is necessary IMHO because there is no default semantics for comparing nil with something else (depending on my specific use case I might have chosen to return true in the nil case).</span></font></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></font></div><div class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">-Thorsten </span></font></div></div></div><div class=""><div class=""><div class=""><br class=""></div></div></div><div class=""><br class=""></div><div class="">Am 09.12.2015 um 13:03 schrieb Al Skipp via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class="">I don’t have a problem with Optionals being comparable, but I do see the potential for bugs occurring as Swift automatically wraps values as Optionals when required. Not sure what the solution would be here, other than to make the wrapping of values explicit?<div class=""><br class=""></div><div class="">Here’s an example of when automatic Optional wrapping can cause unexpected results:</div><div class=""><br class=""></div><div class=""><div class="">struct Pet {</div><div class=""> let age: Int</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Person {</div><div class=""> let name: String</div><div class=""> let pet: Pet?</div><div class="">}</div><div class=""><br class=""></div><div class="">let peeps = [</div><div class=""> Person(name: "Fred", pet: Pet(age: 5)),</div><div class=""> Person(name: "Jill", pet: .None), // no pet here</div><div class=""> Person(name: "Burt", pet: Pet(age: 10)),</div><div class="">]</div><div class=""><br class=""></div><div class="">let ps = peeps.filter { $0.pet?.age < 6 }</div><div class=""><br class=""></div><div class="">ps == [Fred, Jill] // if you don’t own a pet, your non-existent pet is considered to be younger than any actual pet 🐶</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">If the Optional wrapping of ‘6’ in the comparison had to be explicit, then the result wouldn't be so unexpected.</div><div class=""><br class=""></div><div class="">Al</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class=""><blockquote type="cite" class=""><div class="">On 9 Dec 2015, at 11:31, Lucas Derraugh <<a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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;" class="">This is related to a question I asked on SO a while back: <a href="http://stackoverflow.com/questions/26172911/swift-nil-has-a-numeric-value" class="">http://stackoverflow.com/questions/26172911/swift-nil-has-a-numeric-value</a></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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;" class="">Seems that many others have had confusion with the same problem, and it can sneak into your code without being aware of it. The simple case that I ran into was comparing an Optional Int to an Int. It is a very subtle bug and one that I don’t think should be allowed to occur. To me the intent isn't clear in this situation. I don’t think nil should be considered true or false if compared against. The only alternative I can think of is if comparing anything to a nil value, the result would be false; this would probably still lead to unexpected behavior though.</div><br style="font-family: Helvetica, Arial; font-size: 13px; 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;" class=""><div id="bloop_sign_1449659971674371072" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><div style="font-family: helvetica, arial; font-size: 13px;" class="">Lucas Derraugh<br class=""><a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a></div><div style="font-family: helvetica, arial; font-size: 13px;" class="">607-793-3517<span class="Apple-tab-span" style="white-space: pre;">        </span></div></div><br style="font-family: Helvetica, Arial; font-size: 13px; 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;" class=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; 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;">On December 9, 2015 at 6:10:40 AM, Al Skipp via swift-evolution (<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>) wrote:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><span class=""><div class=""></div><blockquote type="cite" class=""><pre class="" style="white-space: pre-wrap; background-color: rgb(255, 255, 255);">To me it seems logical that comparing Optional<Int> with Int (or another
Optional<Int>), if it's allowed at all, should return Optional<Bool>. Since
conditional statements only accept Bool, the user is forced to handle the
nil case explicitly.
</pre></blockquote><div class="">I disagree that comparing Optional values should have a return value of Optional<Bool>.</div><div class="">If the following were to be true:</div><div class=""><br class=""></div><div class="">.None < .Some(0) == .None</div><div class=""><br class=""></div><div class="">Then logically, this would be too:</div><div class=""><br class=""></div><div class="">[] < [1,2,3] == []</div><div class=""><br class=""></div><div class="">I think most people would agree that the correct result to that comparison should be ‘true’, not [].</div><div class=""><br class=""></div><div class="">When comparing ‘container’ types I think it’s important to have a simple Bool result, otherwise things get very peculiar (conceptually the Optional type is really just a container with a maximum count of 1).</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=jmhDxcaxa3uq2rlI6BgFHRrxrj-2Bs36SiRq7BRdjtWBvMfe1Bm7ILNxUSz6dnTlNGKB0U9un-2BJw43J8Eug-2B6e94KXSHEs43BltcCxCL6xHZ6Vz1je-2BF71w2PPuurExpuEpjqFTe40gYXr7THh6c-2BHg4bIcUB-2BLxd9Pi-2F2ACvc8lOR4hLv1rzUc-2FiNHhsHSn9RC2rrnH-2F5fsg2Df-2FFV-2BPEdyLAhCTgeivUcNNBL-2F6RjDE-3D" alt="" width="1" height="1" border="0" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" 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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></blockquote></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Z0lfE0AvBRKWSDAcltP5-2FwA6tH7CtZqjBw6KQdxzh8UeEAuMESPncyStoaIO7wH-2B9f-2FOOzKtPWKdGFHzZT5B6eE5kvJZg12MevMi0OiNUfsDohlrJjb-2F-2FdikUkGl8wLSxPQsqyvPFlYx5rj-2Fx2MnI4MDir30TsEj5YMIrHW1Z-2F3rTfUhvMvENLbuVSU0sar3e-2FajKDsU2xd9C6Su5fLPLVy4RK4NLIf3IEu9dMnrvPkpaA0p0qzmnThDmbR0vkkD" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></body></html>