<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=""><div class="">Another alternative is to use `array = array.filter { $0 != someElement }`.</div><div class=""><br class=""></div><div class="">I thought that there would be a `remove(where:)` method, but there isn't.</div><div class=""><br class=""></div><div class="">Félix</div><br class=""><div><blockquote type="cite" class=""><div class="">Le 25 sept. 2017 à 02:12, Alwyn Concessao via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><!--[if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]--><div class=""><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;" class=""><div id="ydpd3132f34yiv4746156552" class=""><!--[if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]--><div class=""><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;" class=""><div class="">Hello,</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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=""><br class=""></div><div class="">The prototype of the methods will be as follows - </div><div class=""><br class=""></div><div class="">extension RangeReplaceableCollection where Element:Equatable{</div><div class=""><br class=""></div><div class="">mutating func removeElement(_ elementToBeRemoved:Element){</div><div class=""><br class=""></div><div class="">//check if elementToBeRemoved exists ;if yes, remove all occurrences of elementsToBeRemoved from the collection.</div><div class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">mutating func removeElementInSubrange(_ elementToBeRemoved:Element,in range:Range<Index>){</div><div class=""><br class=""></div><div class="">//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 class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">mutating func removeContentsOf<C:Collection>(_ elementsToBeRemoved:C){</div><div class=""><br class=""></div><div class="">//check if each element in the elementsToBeRemoved sequence exists in the collection, if the element exists, remove it.</div><div class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">I've implemented the above in the pull request <a href="https://github.com/apple/swift/pull/12058" class="">https://github.com/apple/swift/pull/12058</a> </div><div class=""><br class=""></div><div class="">Any thoughts/suggestions on this are appreciated.</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">Alwyn</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><p style="margin:0px;font-size:22px;line-height:normal;font-family:'Helvetica Neue';color:rgb(19, 55, 255);" class=""></p><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div></div></div></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=""></body></html>