<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=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><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 < 6 } ?? false }</span></font></div></div></div></div></div></blockquote></div></div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><br class=""></div></div></div></div></div></blockquote></div></div></div><div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div 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)</div></div></div></blockquote><div><br class=""></div>You are right, the example does not compile (wrote it in the train far away from Xcode). It gives an error of „value of type ‚Int‘ has no member ‚map‘“.</div><div><br class=""></div><div>Hmm, I consider that as a bug in the definition of optional chaining, as the documentation clearly states </div><div>"Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the property, method, or subscript call succeeds; <b class="">if the optional is nil, the property, method, or subscript call returns nil.</b>“ (note the last sentence).</div><div><br class=""></div><div>So if $0.pet?.age should return nil in case of $0.pet being nil, the type of $0.pet?.age has to be Int? and therefore understand map().<br class=""><br class=""><div style="margin: 0px; font-size: 13px; line-height: normal; color: rgb(211, 54, 130);" class=""><font face="Menlo" class="">peeps</font><span style="font-family: Menlo; color: rgb(131, 148, 150);" class="">[</span><span style="font-family: Menlo; color: rgb(41, 161, 152);" class="">0</span><span style="font-family: Menlo; color: rgb(131, 148, 150);" class="">].</span><font face="Menlo" class="">pet</font><span style="font-family: Menlo; color: rgb(131, 148, 150);" class="">?.</span><font face="Menlo" class="">age</font><span style="font-family: Menlo; color: rgb(131, 148, 150);" class="">.</span><span style="font-family: Menlo; color: rgb(133, 153, 1);" class="">dynamicType </span><span style="color: rgb(88, 110, 117);" class="">// => Int.Type this is wrong!! Should be Optional<Int>.Type</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; color: rgb(211, 54, 130);" class=""><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-family: Menlo; color: rgb(133, 153, 1);" class="">let</span><font face="Menlo" class=""> y: </font><span style="font-family: Menlo; color: rgb(181, 137, 1);" class="">Int</span><font face="Menlo" class=""> = </font><span style="font-family: Menlo; color: rgb(211, 54, 130);" class="">peeps</span><font face="Menlo" class="">[</font><span style="font-family: Menlo; color: rgb(41, 161, 152);" class="">1</span><font face="Menlo" class="">].pet?.age</font><span style="font-family: Menlo; color: rgb(211, 54, 130);" class=""> </span><span style="color: rgb(88, 110, 117);" class="">// This gives a type error which is right (but inconsistent with the dynamicType just claimed)</span></div></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><span style="color: rgb(133, 153, 1); font-size: 13px; font-family: Menlo;" class="">let</span><font face="Menlo" style="color: rgb(131, 148, 150); font-size: 13px;" class=""> x = </font><span style="color: rgb(211, 54, 130); font-size: 13px; font-family: Menlo;" class="">peeps</span><font face="Menlo" style="color: rgb(131, 148, 150); font-size: 13px;" class="">[</font><span style="color: rgb(41, 161, 152); font-size: 13px; font-family: Menlo;" class="">1</span><font face="Menlo" style="color: rgb(131, 148, 150); font-size: 13px;" class="">].</font><span style="color: rgb(211, 54, 130); font-size: 13px; font-family: Menlo;" class="">pet</span><font face="Menlo" style="color: rgb(131, 148, 150); font-size: 13px;" class="">?.</font><span style="color: rgb(211, 54, 130); font-size: 13px; font-family: Menlo;" class="">age </span><font color="#586e75" size="2" class="">// Now let’s see what the type is after assigning the expression</font></div><div style="margin: 0px; font-size: 13px; line-height: normal; color: rgb(133, 153, 1);" class=""><span style="font-family: Menlo; color: rgb(211, 54, 130);" class="">x</span><span style="font-family: Menlo; color: rgb(131, 148, 150);" class="">.</span><font face="Menlo" class="">dynamicType </font><span style="color: rgb(88, 110, 117);" class="">// =></span><span style="color: rgb(88, 110, 117);" class=""> Optional<Int>.Type as expected</span></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-family: Menlo; color: rgb(211, 54, 130);" class="">x</span><font face="Menlo" class="">.</font><span style="font-family: Menlo; color: rgb(108, 113, 196);" class="">map</span><font face="Menlo" class=""> { age </font><span style="font-family: Menlo; color: rgb(133, 153, 1);" class="">in</span><font face="Menlo" class=""> age < </font><span style="font-family: Menlo; color: rgb(41, 161, 152);" class="">6</span><font face="Menlo" class=""> } ?? </font><span style="font-family: Menlo; color: rgb(133, 153, 1);" class="">false </span><span style="color: rgb(88, 110, 117);" class="">// =></span><span style="color: rgb(88, 110, 117);" class=""> false as expected</span></div></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="color: rgb(88, 110, 117);" class=""><br class=""></span></div><div class="">So, obviously a bug in the compiler.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><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></div></blockquote><div><br class=""></div>You are certainly right that the real issue is with auto wrapping.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><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></div></blockquote><div><br class=""></div>You have me convinced here as the cases for the String and the List are quite convincing and the analogy with .None and .Some compelling.</div><div>Thanks!</div><div><br class=""></div><div>Just checked: Haskell defines the same order for its Maybe monad, i.e. (Nothing < Just 0) == True.</div><div><br class=""></div><div>-Thorsten</div><div><br class=""></div></body></html>