<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Probably would have been better to go with a mutating filter and a non-mutating filtered, terms-of-art be damned. Remove seems like an subpar substitute for that.</div><div><br>On Sep 26, 2017, at 12:55 AM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div>What is the use case?<br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 25, 2017 at 23:27 Félix Cloutier <<a href="mailto:felixcloutier@icloud.com">felixcloutier@icloud.com</a>> wrote:<br></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">Actually, IMO, it's an oversight that there's no remove(where:), or another in-place equivalent to `filter`. I'm in favor of it.<div><br></div><div></div></div><div style="word-wrap:break-word"><div>Félix</div></div><div style="word-wrap:break-word"><div><br><div><br><div><blockquote type="cite"><div>Le 25 sept. 2017 à 15:17, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> a écrit :</div><br class="m_3487363041747758027Apple-interchange-newline"><div><div dir="ltr">On Mon, Sep 25, 2017 at 4:55 PM, Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_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><br>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><br></div><div>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><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_3487363041747758027HOEnZb"><div class="m_3487363041747758027h5"><div class="gmail_quote"><div dir="ltr">On Mon, Sep 25, 2017 at 11:14 Félix Cloutier via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></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"><div>Another alternative is to use `array = array.filter { $0 != someElement }`.</div><div><br></div><div>I thought that there would be a `remove(where:)` method, but there isn't.</div></div><div style="word-wrap:break-word"><div><br></div><div>Félix</div></div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>Le 25 sept. 2017 à 02:12, Alwyn Concessao via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br class="m_3487363041747758027m_-3630028882392956976m_8781221207431004162Apple-interchange-newline"><div><div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:13px"><div id="m_3487363041747758027m_-3630028882392956976m_8781221207431004162ydpd3132f34yiv4746156552"><div><div style="font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:13px"><div>Hello,</div><div><br></div><div>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'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'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><br></div><div>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><br></div><div>The prototype of the methods will be as follows - </div><div><br></div><div>extension RangeReplaceableCollection where Element:Equatable{</div><div><br></div><div>mutating func removeElement(_ elementToBeRemoved:Element){</div><div><br></div><div>//check if elementToBeRemoved exists ;if yes, remove all occurrences of elementsToBeRemoved from the collection.</div><div><br></div><div>}</div><div><br></div><div>mutating func removeElementInSubrange(_ elementToBeRemoved:Element,in range:Range<Index>){</div><div><br></div><div>//check if elementoBeRemoved exists; if yes, check if the index of elementToBeRemoved is part of the subrange, if yes then remove else don't remove.</div><div><br></div><div>}</div><div><br></div><div>mutating func removeContentsOf<C:Collection>(_ elementsToBeRemoved:C){</div><div><br></div><div>//check if each element in the elementsToBeRemoved sequence exists in the collection, if the element exists, remove it.</div><div><br></div><div>}</div><div><br></div><div>I've implemented the above in the pull request <a href="https://github.com/apple/swift/pull/12058" target="_blank">https://github.com/apple/swift/pull/12058</a> </div><div><br></div><div>Any thoughts/suggestions on this are appreciated.</div><div><br></div><div>Thanks!</div><div><br></div><div>Alwyn</div><div><br></div><div><br></div><div><br></div><div><br><p style="margin:0px;font-size:22px;line-height:normal;font-family:'Helvetica Neue';color:rgb(19,55,255)"></p><div><br></div><div><br></div></div></div></div></div></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div></div></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></div></blockquote></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>