<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I also cast my vote for filterMap. It’s concise, understandable and is kind of a term of art also.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 24 Oct 2017, at 02:56, BJ Homer via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class="">I agree with Xiaodi; I like ‘filterMap’ more than ‘filteredMap’. But both are superior to ‘flatMap’ in this context.<br class=""><br class=""><div class="">-BJ</div><div class=""><br class="">On Oct 23, 2017, at 5:22 PM, Max Moiseev <<a href="mailto:moiseev@apple.com" class="">moiseev@apple.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">It occurred to me that filteringMap(_:) should be even more descriptive, still conform to the guidelines, although similarly unprecedented and un-googlable.<div class=""><br class=""></div><div class="">Max<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 23, 2017, at 3:52 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">+1 in general. As to the name: since 'map' is used as a term of art, 'filterMap' seems superior to 'filteredMap', which half follows naming guidelines and half is a term of art; neither is immediately comprehensible but 'filterMap' can be googled and has precedents in other languages.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Mon, Oct 23, 2017 at 17:24 BJ Homer via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">I strongly agree! In fact, I just started writing up a similar proposal the other day, but hadn’t had time to finish it yet.<div class=""><br class=""></div><div class="">The current name for this particular filtering variant is not particularly descriptive. It’s certainly not obvious to newcomers that ‘flatMap’ will filter out results. And it’s not true to the existing usage of ‘flatMap' from other languages; you have to really squint at it to see how any “flattening” is happening at all.</div><div class=""><br class=""></div><div class="">So yes, a big +1 from me. Thanks!</div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""></div><div class="">-BJ Homer</div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Oct 23, 2017, at 4:15 PM, Max Moiseev via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class="m_-3167177071233817278Apple-interchange-newline"><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class="">Hi swift-evolution!<div class=""><br class=""></div><div class="">I would like to propose the following change to the standard library:</div><div class=""><br class=""></div><div class="">deprecate `Sequence.flatMap<U>(_: (Element) -> U?) -> [U]` and make this functionality available under a new name `Sequence.filteredMap(_:)`.</div><div class=""><br class=""></div><div class="">The draft is available at <a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95" target="_blank" class="">https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95</a> and is included below for your convenience.</div><div class=""><br class=""></div><div class="">Max</div><div class=""><br class=""></div><div class=""><h1 style="box-sizing:border-box;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255);margin-top:0px!important" class="">Introduce Sequence.filteredMap(_:)</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class=""><li style="box-sizing:border-box" class="">Proposal: <a href="https://gist.github.com/moiseev/NNNN-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">SE-NNNN</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Authors: <a href="https://github.com/moiseev" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">Max Moiseev</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Review Manager: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="">Status: <span style="box-sizing:border-box;font-weight:600" class="">Awaiting implementation</span></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#introduction" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">We propose to deprecate the controversial version of a <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Sequence.flatMap</code> method and provide the same functionality under a different, and potentially more descriptive, name.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#motivation" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">The Swift standard library currently defines 3 distinct overloads for <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code>:</p><div class="m_-3167177071233817278highlight m_-3167177071233817278highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Sequence</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">flatMap</span><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)"><</span>S<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span>(<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">_</span>: (<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Element</span>) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> S) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> [S.<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Element</span>]
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">where</span> S <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Sequence</span>
<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Optional</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">flatMap</span><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)"><</span>U<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span>(<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">_</span>: (Wrapped) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> U<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span>) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> U<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span>
<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Sequence</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">flatMap</span><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)"><</span>U<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">></span>(<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">_</span>: (<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Element</span>) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> U<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">?</span>) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> [U]</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">The last one, despite being useful in certain situations, can be (and often is) misused. Consider the following snippet:</p><div class="m_-3167177071233817278highlight m_-3167177071233817278highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">struct</span> <span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">Person</span> {
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> age<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Int</span>
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">var</span> name<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span> <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">String</span>
}
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">getAges</span>(<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box"><span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">people</span></span>: [Person]) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> [<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Int</span>] {
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> people.<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">flatMap</span> { <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">$0</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">age</span> }
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">What happens inside <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">getNames</code> is: thanks to the implicit promotion to <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Optional</code>, the result of the closure gets wrapped into a <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">.some</code>, then immediately unwrapped by the implementation of <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code>, and appended to the result array. All this unnecessary wrapping and unwrapping can be easily avoided by just using <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">map</code> instead.</p><div class="m_-3167177071233817278highlight m_-3167177071233817278highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">getAges</span>(<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box"><span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">people</span></span>: [Person]) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> [<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Int</span>] {
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> people.<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">map</span> { <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">$0</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">age</span> }
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">It gets even worse when we consider future code modifications, like the one where Swift 4 introduced a <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">String</code>conformance to the <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Collection</code> protocol. The following code used to compile (due to the <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code> overload in question).</p><div class="m_-3167177071233817278highlight m_-3167177071233817278highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">getNames</span>(<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box"><span class="m_-3167177071233817278pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">people</span></span>: [Person]) <span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-></span> [<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">String</span>] {
<span class="m_-3167177071233817278pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">return</span> people.<span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">flatMap</span> { <span class="m_-3167177071233817278pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">$0</span>.<span class="m_-3167177071233817278pl-smi" style="box-sizing:border-box">name</span> }
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">But it no longer does, because now there is a better overload that does not involve implicit promotion. In this particular case, the compiler error would be obvious, as it would point at the same line where <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code> is used. Imagine however if it was just a <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">let names = people.flatMap { $<a href="http://0.name/" target="_blank" class="">0.name</a> }</code> statement, and the <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">names</code> variable were used elsewhere. The compiler error would be misleading.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#proposed-solution" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">We propose to deprecate the controversial overload of <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code> and re-introduce the same functionality under a new name. The name being <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">filteredMap(_:)</code> as we believe it best describes the intent of this function.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">For reference, here are the alternative names from other languages:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class=""><li style="box-sizing:border-box" class="">Haskell, Idris <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">
mapMaybe :: (a -> Maybe b) -> [a] -> [b]</code></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Ocaml (Core and Batteries)
<code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">filter_map : 'a t -> f:('a -> 'b option) -> 'b t</code></li><li style="box-sizing:border-box;margin-top:0.25em" class="">F#
<code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">List.choose : ('T -> 'U option) -> 'T list -> 'U list</code></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Rust
<code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where F: FnMut(Self::Item) -> Option<B></code></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Scala <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">
def collect[B](pf: PartialFunction[A, B]): List[B]</code></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#source-compatibility" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-source-compatibility" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Source compatibility</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">Since the old function will still be available (although deprecated) all the existing code will compile, producing a deprecation warning and a fix-it.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#effect-on-abi-stability" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-effect-on-abi-stability" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Effect on ABI stability</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">This is an additive API change, and does not affect ABI stability.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#effect-on-api-resilience" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-effect-on-api-resilience" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Effect on API resilience</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">Ideally, the deprecated <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">flatMap</code> overload would not exist at the time when ABI stability is declared, but in the worst case, it will be available in a deprecated form from a library post-ABI stability.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";background-color:rgb(255,255,255)" class=""><a href="https://gist.github.com/moiseev/2f36376c8ef4c2b1273cff0bfd9c3b95#alternatives-considered" class="m_-3167177071233817278anchor" id="m_-3167177071233817278user-content-alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>Alternatives considered</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">It was attempted in the past to warn about this kind of misuse and do the right thing instead by means of a deprecated overload with a non-optional-returning closure. The attempt failed due to another implicit promotion (this time to <code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Any</code>).</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255)" class="">The following alternative names for this function were considered:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important" class=""><li style="box-sizing:border-box" class=""><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">mapNonNil(_:)
</code> Does not communicate what happens to nil’s</li><li style="box-sizing:border-box;margin-top:0.25em" class=""><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">mapSome(_:)
</code> Reads more like «map some elements of the sequence, but not the others» rather than «process only the ones that produce an Optional.some»</li><li style="box-sizing:border-box;margin-top:0.25em" class=""><code style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">filterMap(_:)</code>
Does not really follow the naming guidelines and doesn’t seem to be common enough to be considered a term of art.</li></ul><div class=""><br class=""></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></blockquote></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=""></div></body></html>