<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>On Tue, Nov 7, 2017, at 05:23 PM, Tino Heth via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>-1<br></div>
<div><br></div>
<div>I guess breaking existing code will be the show stopper for this proposal — but I generally think that compatibility is a poor rationale to stop an improvement, so my personal reasons are different:<br></div>
<div>The name is just wrong.<br></div>
<div>Just have a look at this simple example<br></div>
<div><br></div>
<div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;font-family:Menlo;color:rgb(186, 45, 162);background-color:rgb(255, 255, 255);"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;">extension<span class="colour" style="color:rgb(0, 0, 0)"> </span><span class="colour" style="color:rgb(112, 61, 170)">Int</span><span class="colour" style="color:rgb(0, 0, 0)"> {</span><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);"> <span class="colour" style="color:rgb(186, 45, 162)">func</span> justImagineError() <span class="colour" style="color:rgb(186, 45, 162)">throws</span> -> <span class="colour" style="color:rgb(112, 61, 170)">Int</span> {<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;"><span class="colour" style="color:rgb(0, 0, 0)"> </span>return<span class="colour" style="color:rgb(0, 0, 0)"> </span>self<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);"> }<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);">}<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;font-family:Helvetica;min-height:14px;"><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);"><span class="colour" style="color:rgb(186, 45, 162)">let</span> ints: [<span class="colour" style="color:rgb(112, 61, 170)">Int</span>?] = [<span class="colour" style="color:rgb(186, 45, 162)">nil</span>]<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;font-family:Helvetica;min-height:14px;"><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);"><span class="colour" style="color:rgb(186, 45, 162)">let</span> result = <span class="colour" style="color:rgb(79, 129, 135)">ints</span>.<span class="colour" style="color:rgb(62, 30, 129)">flatMap</span> {<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(49, 89, 93);"><span class="colour" style="color:rgb(0, 0, 0)"> </span><span class="colour" style="color:rgb(186, 45, 162)">return</span><span class="colour" style="color:rgb(0, 0, 0)"> </span><span class="colour" style="color:rgb(186, 45, 162)">try</span><span class="colour" style="color:rgb(0, 0, 0)">? $0?.</span>justImagineError<span class="colour" style="color:rgb(0, 0, 0)">()</span><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(0, 0, 0);">}<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-stretch:normal;line-height:normal;color:rgb(79, 129, 135);"><span class="colour" style="color:rgb(62, 30, 129)">print</span><span class="colour" style="color:rgb(0, 0, 0)">(</span>result<span class="colour" style="color:rgb(0, 0, 0)">)</span><br></div>
<div><span class="colour" style="color:rgb(0, 0, 0)"></span><br></div>
</div>
</div>
</div>
<div>If flatMap would really filter out nil values, this should yield an empty array as result — but the actual output is <b style="font-family:Menlo;">[nil]</b><br></div>
</blockquote><div><br></div>
<div>flatMap does filter out nil values. The problem is the return type of your block is `Int??`, not `Int?`, so it's stripping off the outer layer of optionals. Your example here is akin to one where your block returns `[[[Int]]]` and asking why your resulting type is `[[Int]]`.</div>
<div><br></div>
<div>-Kevin Ballard</div>
</body>
</html>