<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="">Am 10.11.2017 um 23:32 schrieb Max Moiseev <<a href="mailto:moiseev@apple.com" class="">moiseev@apple.com</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);"><span class="" style="color: rgb(186, 45, 162);">extension</span><span class=""><span class="Apple-converted-space"> </span></span>Collection<span class=""><span class="Apple-converted-space"> </span>{</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(186, 45, 162);">func</span><span class="Apple-converted-space"> </span>filterMap<T>(transform: (<span class="" style="color: rgb(112, 61, 170);">Element</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">T</span>, include: (<span class="" style="color: rgb(79, 129, 135);">T</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">Bool</span>) -> [<span class="" style="color: rgb(79, 129, 135);">T</span>] {</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="Apple-tab-span" style="white-space: pre;">                </span><span class="" style="color: rgb(186, 45, 162);">return</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">self</span>.<span class="" style="color: rgb(62, 30, 129);">map</span>(transform).<span class="" style="color: rgb(62, 30, 129);">filter</span>(include)</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">}</div></div></div></div></blockquote><div 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;" class=""><br class=""></div><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="">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{}` ?</span></div></div></div></blockquote></div><br class=""><div class="">I didn’t want to write any additional posts in this thread ;-), but as you ask a concrete question:</div><div class="">Imho there isn't any benefit over just using the two methods — it might be different for special cases with default values for one of the parameters (like getting rid of NaN, Zero or Infinity in a collection of floats), but I wouldn’t expect any of those to be part of the stdlib.</div><div class="">It’s just that this function is the natural interpretation of its name (especially for someone who knows flatMap), and I encountered people who are convinced that flatMap on Collections of Optionals is just like that: You map, you filter, you return the result (some even thought it’s the other way round, filtering being the first step).</div><div class="">Please note that the actual implementation of the method doesn’t matter at all for me — what matters is expectation (after all, I wouldn’t rename flatMap to joinMap), and the expectation for a filter is quite clear.</div><div class=""><br class=""></div><div class="">What kept the dispute alive that long is not that much that I think filterMap is a bad name per se, it is the widespread belief that it is a better description than flatMap.</div><div class="">Me and others strongly disagree here, and I’m quite sure no argument can change my mind on that. Therefor, the whole basis of the discussion is flawed, and I would be quite disappointed if the rationale for the acceptance of this proposal would be that flatMap is a wrong name, and filterMap is correct.</div><div class="">The real question should be if the renaming is beneficial for developers — and in this regard, wrong beliefs can work as good a good as true ones: As many people seem to have the same misconception about flatMap, it might be better to accept that (although I would like to see Kevin Ballards idea implemented anyways).</div><div class=""><br class=""></div><div class="">Concatenation is such a case: It doesn’t follow the laws of addition at all, but still, the same operator that is well established for adding numbers was chosen for it, because of the popular believe that joining two collections is like adding two numbers.</div><div class=""><br class=""></div><div class="">Tino</div></body></html>