<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="">The pet example took a while to digest. Not really intuitive, but makes sense when thinking it through.</div>
<div class=""><br class="">
</div>
<div class="">BTW, thank you for &quot;Swift Adventures In Monad Land&quot;, Al :-)</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 09.12.2015, at 19:30, Al Skipp 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
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="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; 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 class="">let ps = peeps.filter { $0.pet.map { pet in pet.age &lt; 6 } ?? false }</div>
</div>
<div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
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="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
Regarding the default semantics, I’d say the semantics of Optional comparison is pretty reasonable and fits with:</div>
<div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; 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 class="">&quot;&quot; &lt; &quot;abc&quot; == true</div>
<div class="">[] &lt; [1,2,3] == true</div>
<div class="">.None &lt; .Some(0) == true</div>
</div>
<div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">
Al</div>
<div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; 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>
<br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">
<blockquote type="cite" class="">
<div class="">On 9 Dec 2015, at 17:44,<span class="Apple-converted-space">&nbsp;</span><a href="mailto:thorsten@portableinnovations.de" class="">thorsten@portableinnovations.de</a><span class="Apple-converted-space">&nbsp;</span>wrote:</div>
<br class="Apple-interchange-newline">
<div 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 class="" style="background-color: rgba(255, 255, 255, 0);">let ps = peeps.filter { $0.pet?.age.map { age in age &lt; 6 } ?? false }</span></font></div>
<div class=""><font class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class="">
</span></font></div>
<div class=""><font class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">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 class="" style="background-color: rgba(255, 255, 255, 0);"><br class="">
</span></font></div>
<div class=""><font class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">-Thorsten&nbsp;</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 &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class="">
<br class="">
</div>
<blockquote type="cite" class="">
<div 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="">&nbsp; let age: Int</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">struct Person {</div>
<div class="">&nbsp; let name: String</div>
<div class="">&nbsp; let pet: Pet?</div>
<div class="">}</div>
<div class=""><br class="">
</div>
<div class="">let peeps = [</div>
<div class="">&nbsp; Person(name: &quot;Fred&quot;, pet: Pet(age: 5)),</div>
<div class="">&nbsp; Person(name: &quot;Jill&quot;, pet: .None), // no pet here</div>
<div class="">&nbsp; Person(name: &quot;Burt&quot;, pet: Pet(age: 10)),</div>
<div class="">]</div>
<div class=""><br class="">
</div>
<div class="">let ps = peeps.filter { $0.pet?.age &lt; 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 &nbsp;🐶</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 &lt;<a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div id="bloop_customfont" class="" 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;">
This is related to a question I asked on SO a while back:&nbsp;<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" class="" 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;">
<br class="">
</div>
<div id="bloop_customfont" class="" 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;">
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 class="" 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 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 class="" style="font-family: helvetica, arial; font-size: 13px;">Lucas Derraugh<br class="">
<a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a></div>
<div class="" style="font-family: helvetica, arial; font-size: 13px;">607-793-3517<span class="Apple-tab-span" style="white-space: pre;">
</span></div>
</div>
<br class="" 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;">
<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&lt;Int&gt; with Int (or another
Optional&lt;Int&gt;), if it's allowed at all, should return Optional&lt;Bool&gt;. 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&lt;Bool&gt;.</div>
<div class="">If the following were to be true:</div>
<div class=""><br class="">
</div>
<div class="">.None &lt; .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="">[] &lt; [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" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">&nbsp;_______________________________________________<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" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></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="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=z8-2FItS9d607zlxyiqd-2BXa09jaXmO60VXV2wLjA8i2wn5Fm7RtiY1ZRKyR2xaCpjJmQjEW0o2zDh1jLnbyGW5B1P6fNyBlpbgkdWt02TJANMObshv7gbH9YmS2wLgdGkVbYRjiJbPhbDqLLOnr4-2FKKkga05-2FNSWnfk2ltKqtX197ZQf-2ByRGsFGCG0qyWcZAj3DbqQetlOphqHwdBUKbua22uTjW87uTp2Bcg9xhdLa4s-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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; float: none; display: inline !important;" class="">swift-evolution
 mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">
<a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div>
</blockquote>
</div>
<br class="">
</body>
</html>