<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 <<a href="mailto:2th@gmx.de" class="">2th@gmx.de</a>> 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<T>(transform: (<span style="color: #703daa" class="">Element</span>) -> <span style="color: #4f8187" class="">T</span>, include: (<span style="color: #4f8187" class="">T</span>) -> <span style="color: #703daa" class="">Bool</span>) -> [<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 class=""><br class=""></div></div></div></blockquote></div><br class=""><div class="">If you insist upon a literal translation of the name into code, then here:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">extension<span style="color: #000000" class=""> </span><span style="color: #703daa" class="">Sequence</span><span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">func</span> filterMap<T>(<span style="color: #ba2da2" class="">_</span> transform: (<span style="color: #703daa" class="">Element</span>)-><span style="color: #4f8187" class="">T</span>?) -> [<span style="color: #4f8187" class="">T</span>] {</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>.<span style="color: #3e1e81" class="">filter</span> { transform($0) != <span style="color: #ba2da2" class="">nil</span> }.<span style="color: #3e1e81" class="">map</span> { transform($0)! }</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">The implementor is then able to optimize that implementation however they prefer.</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>