<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div><div><div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;"></div>
            <div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;">First of all thanks to you all for the suggestions/thoughts on this idea.</div><div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;"><br></div><div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;">@Jonathan Hull - You've mentioned &nbsp;about splitting a list using a filter which returns the filtered list and the remainder.Is it similar to having a filter function which does the filtering on the original collection and also returns the elements which are removed from the collection?<br></div><div style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px;"><br></div><div>@Félix Cloutier and @Robert Bennett - &nbsp;Yes, in-place filter method is not provided by Swift.The in-place filter method would also take care of removing elements without actually accessing it's index.</div><div><br></div><div>Alwyn</div>
            
            </div></div></div></div></div><div id="yahoo_quoted_7158320797" class="yahoo_quoted">
                <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                    
                    <div>
                        On Tuesday, 26 September 2017, 12:00:23 PM IST, Félix Cloutier &lt;felixcloutier@icloud.com&gt; wrote:
                    </div>
                    <div><br></div>
                    <div><br></div>
                    <div><div id="yiv3928029498"><html><head></head><div>Same as `filter`, but in-place. We thought that `sorted` deserved an in-place version; that +(Array, Array) deserved an in-place version (append(contentsOf:)); there are parallels to be made between `dropFirst` and `removeFirst`; we have index and formIndex. There&#39;s a ton more, Swift loves to have a mutating and a non-mutating version of everything. Not sure why we should break consistency and not have an in-place version of filter.<div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">Félix<br clear="none" class="yiv3928029498"><div class="yiv3928029498yqt5639160790" id="yiv3928029498yqt55991"><div><br clear="none" class="yiv3928029498"><blockquote class="yiv3928029498" type="cite"><div class="yiv3928029498">Le 25 sept. 2017 à 21:55, Xiaodi Wu &lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:xiaodi.wu@gmail.com" target="_blank" href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; a écrit :</div><br clear="none" class="yiv3928029498Apple-interchange-newline"><div class="yiv3928029498">What is the use case?<br clear="none" class="yiv3928029498"><div class="yiv3928029498gmail_quote"><div class="yiv3928029498" dir="ltr">On Mon, Sep 25, 2017 at 23:27 Félix Cloutier &lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:felixcloutier@icloud.com" target="_blank" href="mailto:felixcloutier@icloud.com">felixcloutier@icloud.com</a>&gt; wrote:<br clear="none" class="yiv3928029498"></div><blockquote class="yiv3928029498gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="yiv3928029498" style="word-wrap:break-word;">Actually, IMO, it&#39;s an oversight that there&#39;s no remove(where:), or another in-place equivalent to `filter`. I&#39;m in favor of it.<div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"></div></div><div class="yiv3928029498" style="word-wrap:break-word;"><div class="yiv3928029498">Félix</div></div><div class="yiv3928029498" style="word-wrap:break-word;"><div class="yiv3928029498"><br clear="none" class="yiv3928029498"><div class="yiv3928029498"><br clear="none" class="yiv3928029498"><div class="yiv3928029498"><blockquote class="yiv3928029498" type="cite"><div class="yiv3928029498">Le 25 sept. 2017 à 15:17, Xiaodi Wu &lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:xiaodi.wu@gmail.com" target="_blank" href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt; a écrit :</div><br clear="none" class="yiv3928029498m_3487363041747758027Apple-interchange-newline"><div class="yiv3928029498"><div class="yiv3928029498" dir="ltr">On Mon, Sep 25, 2017 at 4:55 PM, Xiaodi Wu <span class="yiv3928029498" dir="ltr">&lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:xiaodi.wu@gmail.com" target="_blank" href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br clear="none" class="yiv3928029498"><div class="yiv3928029498gmail_extra"><div class="yiv3928029498gmail_quote"><blockquote class="yiv3928029498gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Brent has a great proposal in the pipeline regularizing the names of some of these functions and filling in some of the more glaring gaps.<br clear="none" class="yiv3928029498"><br clear="none" class="yiv3928029498">With regard to the specific items proposed here, Felix shows that ‘filter’ provides an idiomatic one-line way of doing some of what is proposed; currently remove(index(of:)) and operating on sliced would accomplish the rest. Therefore, I do not think these proposed additions meet the very high bar for expansion of the standard library API.</blockquote><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">I should add, however, it is wonderful (IMO) that more people are thinking about these APIs; welcome and thank you for restarting this very important conversation. It would be nice to get some more eyeballs on the previously discussed set of rationalizations to the Collection APIs so that we can make their use a little more ergonomic--with any luck, some better names for existing extension methods and filling in a very few gaps judiciously would allow us to make the existing facilities sufficiently more discoverable that it will be easier to accomplish what you seek without adding more extensions.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><blockquote class="yiv3928029498gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="yiv3928029498m_3487363041747758027HOEnZb"><div class="yiv3928029498m_3487363041747758027h5"><div class="yiv3928029498gmail_quote"><div class="yiv3928029498" dir="ltr">On Mon, Sep 25, 2017 at 11:14 Félix Cloutier via swift-evolution &lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br clear="none" class="yiv3928029498"></div><blockquote class="yiv3928029498gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="yiv3928029498" style="word-wrap:break-word;"><div class="yiv3928029498">Another alternative is to use `array = array.filter { $0 != someElement }`.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">I thought that there would be a `remove(where:)` method, but there isn&#39;t.</div></div><div class="yiv3928029498" style="word-wrap:break-word;"><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">Félix</div></div><div class="yiv3928029498" style="word-wrap:break-word;"><br clear="none" class="yiv3928029498"><div class="yiv3928029498"><blockquote class="yiv3928029498" type="cite"><div class="yiv3928029498">Le 25 sept. 2017 à 02:12, Alwyn Concessao via swift-evolution &lt;<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; a écrit :</div><br clear="none" class="yiv3928029498m_3487363041747758027m_-3630028882392956976m_8781221207431004162Apple-interchange-newline"><div class="yiv3928029498"><div class="yiv3928029498"><div class="yiv3928029498" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div class="yiv3928029498" id="yiv3928029498m_3487363041747758027m_-3630028882392956976m_8781221207431004162ydpd3132f34yiv4746156552"><div class="yiv3928029498"><div class="yiv3928029498" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div class="yiv3928029498">Hello,</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">After going through the Swift standard library functions provided for removing elements from a collection, one common pattern can be observed in all those functions and that is the functions provide to remove elements from the collection by passing the position or index of the element or passing a range of indices or positions to remove the elements.The standard library does not provide options to remove an element from a collection by passing the actual element  to be removed directly to the remove method.I&#39;ve encountered this situation many times when programming in Swift wherein I want an element or a set of elements to be removed directly without always accessing it&#39;s index in the collection but I have always ended up having to first access the index of the element or elements which I want to remove and then pass that index to the remove method.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">The idea is to have an extension of the RangeReplaceableCollection protocol to include a method to remove elements from a collection by passing directly the element to be removed to the remove method and also include methods to remove multiple elements from the collection by passing in a sequence of the elements to be removed to the remove method and to remove an element in a particular subrange of the collection.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">The prototype of the methods will be as follows - </div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">extension RangeReplaceableCollection where Element:Equatable{</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">mutating func removeElement(_ elementToBeRemoved:Element){</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">//check if elementToBeRemoved exists ;if yes, remove all occurrences of elementsToBeRemoved from the collection.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">}</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">mutating func removeElementInSubrange(_ elementToBeRemoved:Element,in range:Range&lt;Index&gt;){</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">//check if elementoBeRemoved exists; if yes, check if the index of elementToBeRemoved is part of the subrange, if yes then remove else don&#39;t remove.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">}</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">mutating func removeContentsOf&lt;C:Collection&gt;(_ elementsToBeRemoved:C){</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">//check if each element in the elementsToBeRemoved sequence exists in the collection, if the element exists, remove it.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">}</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">I&#39;ve implemented the above in the pull request <a rel="nofollow" shape="rect" class="yiv3928029498" target="_blank" href="https://github.com/apple/swift/pull/12058">https://github.com/apple/swift/pull/12058</a> </div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">Any thoughts/suggestions on this are appreciated.</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">Thanks!</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498">Alwyn</div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"><p class="yiv3928029498" style="margin:0px;font-size:22px;line-height:normal;font-family:'Helvetica Neue';color:rgb(19,55,255);"></p><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div><div class="yiv3928029498"><br clear="none" class="yiv3928029498"></div></div></div></div></div></div></div>_______________________________________________<br clear="none" class="yiv3928029498">swift-evolution mailing list<br clear="none" class="yiv3928029498"><a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br clear="none" class="yiv3928029498"><a rel="nofollow" shape="rect" class="yiv3928029498" target="_blank" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br clear="none" class="yiv3928029498"></div></blockquote></div><br clear="none" class="yiv3928029498"></div>_______________________________________________<br clear="none" class="yiv3928029498">
swift-evolution mailing list<br clear="none" class="yiv3928029498">
<a rel="nofollow" shape="rect" class="yiv3928029498" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br clear="none" class="yiv3928029498">
<a rel="nofollow" shape="rect" class="yiv3928029498" target="_blank" href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br clear="none" class="yiv3928029498">
</blockquote></div></div></div></blockquote></div><br clear="none" class="yiv3928029498"></div></div>
</div></blockquote></div><br clear="none" class="yiv3928029498"></div></div></div></blockquote></div>
</div></blockquote></div></div><br clear="none" class="yiv3928029498"></div></div></html></div></div>
                </div>
            </div></div></body></html>