<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><br class=""><blockquote type="cite" class=""><div class="">On Nov 10, 2017, at 4:07 AM, Tino Heth 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=""><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=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The “think of optionals as collections” explanation is a good way to help people who are confused by the overload. But an even better way would be to not have a confusing overload in the first place.</span><br class="Apple-interchange-newline"></div></blockquote></div>With the renaming, confusion might strike less often, but with bigger impact (free translation of a real discussion):<div class="">A: Cool, filterMap makes much more sense than flatMap!</div><div class="">Me: Why do you thing so?</div><div class="">A: Well, it does a mapping, and then applies a filter to get rid of nils, and that's super useful!</div><div class="">Me: I see. So you can be sure that when you apply the filterMap method, the result doesn’t contain any nil values?</div><div class="">A: Don’t you understand the concept of a filter? Of course, that’s what I just said, you never have to worry about nil!</div><div class=""><br class=""></div><div class="">[me shows a very simple proof that this is completely wrong]</div><div class=""><br class=""></div><div class="">Even here on the mailing lists, people seem to have a wrong understanding of what flatMap actually does, and this is reinforced with the renaming.</div><div class="">It might have no considerable effect on real-world code, because even with false assumptions, correct results are possible — but I really would prefer to leave the name filterMap free for something like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span><span style="" class=""> </span>Collection<span style="" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #ba2da2" class="">func</span> filterMap&lt;T&gt;(transform: (<span style="color: #703daa" class="">Element</span>) -&gt; <span style="color: #4f8187" class="">T</span>, include: (<span style="color: #4f8187" class="">T</span>) -&gt; <span style="color: #703daa" class="">Bool</span>) -&gt; [<span style="color: #4f8187" class="">T</span>] {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>.<span style="color: #3e1e81" class="">map</span>(transform).<span style="color: #3e1e81" class="">filter</span>(include)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div></div></div></blockquote><div><br class=""></div>I understand the risk of diverging the discussion, but still, what’s the benefit of having this function over using the built-in `.lazy.map{}.filter{}` ?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>