<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 15, 2017, at 3:05 PM, Tino Heth via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div>Odd… exactly that is the reason why I think filterMap is the worst choice:</div></div></blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Both are established terms of art, but one has a meaning that doesn’t fit to the operation.</div><div class="">Applying filter can remove elements, but it can never change types (I feel kind of silly to repeat this over and over, but so far, nobody took the time to falsify this).</div></div></div></blockquote></div><br class=""><div class="">The concern about <font face="Menlo" class="">filter</font> changing types is only relevant if you think of the filter applying to the <i class="">result</i>&nbsp;of the map, instead of being a part of the <font face="Menlo" class="">filterMap</font> operation itself (an operation that is distinct from <font face="Menlo" class="">map</font>).</div><div class=""><br class=""></div><div class="">Let’s imagine that we had this instead:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class=""><span style="color: rgb(186, 45, 162);" class="">enum</span> SelectiveMapResult&lt;T&gt; {</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">case</span> use(<span style="color: #4f8187" class="">T</span>)</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">case</span> ignore</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">}</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><span style="font-size: 11px;" class=""><br class=""></span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">extension<span style="color: #000000" class=""> </span><span style="color: #703daa" class="">Sequence</span><span style="color: #000000" class=""> {</span></span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">func</span> selectiveMap&lt;T&gt;(<span style="color: #ba2da2" class="">_</span> selectiveTransform: (<span style="color: #703daa" class="">Element</span>)-&gt;<span style="color: #4f8187" class="">SelectiveMapResult</span>&lt;<span style="color: #4f8187" class="">T</span>&gt;) -&gt; [<span style="color: #4f8187" class="">T</span>]</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">}</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><span style="font-size: 11px;" class=""><br class=""></span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class=""><span style="color: #ba2da2" class="">let</span> actualNumbers =</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; [<span style="color: #d12f1b" class="">"1"</span>, <span style="color: #d12f1b" class="">"2"</span>, <span style="color: #d12f1b" class="">"apple"</span>, <span style="color: #d12f1b" class="">"banana"</span>, <span style="color: #d12f1b" class="">"5"</span>].<span style="color: #31595d" class="">selectiveMap</span>({ (x)-&gt;<span style="color: #4f8187" class="">SelectiveMapResult</span>&lt;<span style="color: #703daa" class="">Int</span>&gt; <span style="color: #ba2da2" class="">in</span></span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">if</span> <span style="color: #ba2da2" class="">let</span> value = <span style="color: #703daa" class="">Int</span>(x) { <span style="color: #ba2da2" class="">return</span> .<span style="color: #31595d" class="">use</span>(value) }</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">else</span> { <span style="color: #ba2da2" class="">return</span> .<span style="color: #31595d" class="">ignore</span> }</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; })</span></div></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">actualNumbers == [1, 2, 5]</span></div></blockquote><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">The “selective” part of this operation doesn’t feel like it’s changing the type of the result, because <font face="Menlo" class="">SelectiveMapResult</font> is easily understood to not be part of the mapping transformation; it just exists to tell us whether we should <i class="">use the result</i> of that particular transformation. Likewise, I don’t feel like the optional in <font face="Menlo" class="">filterMap</font> is part of the mapping operation; it’s just serving the same role as <font face="Menlo" class="">SelectiveMapResult</font>. (It should be obvious that <font face="Menlo" class="">SelectiveMapResult</font> is just <font face="Menlo" class="">Optional</font> with another name here.)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">The name <font face="Menlo" class="">filterMap</font> focuses on removing the ignored values, as does <font face="Menlo" class="">compactMap</font>. The name <font face="Menlo" class="">selectiveMap</font> focuses on retaining the non-ignored values. I’m not sure whether focusing on the positive or negative aspects is clearer here. I don’t particularly like the name <font face="Menlo" class="">compactMap</font>, simply because I don’t have a lot of experience with languages that use “compact” to mean “drop the nil values”, and without that experience it doesn’t seem intuitive. I think filterMap is better. But if we introduced <font face="Menlo" class="">Sequence.compact()</font> alongside <font face="Menlo" class="">.compactMap()</font>, I’d probably get used to it.</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class="">-BJ</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div></body></html>