You could imagine a `slices` standard library package that has a regular generic function called `slices.Remove` that removes one or a series of elements. This seems like a smart addition to me, as the current de-facto method isn't very expressive. I imagine this didn't exist before because adding a new built-in function has a far higher cost than adding a simple utility function to a package.
On Thu, Feb 4, 2021 at 4:48 PM Uli Kunitz <uli.kun...@gmail.com> wrote: > Hi, > > You can always do a = append(a[:3], a[4:]...). If you want to remove 2 > elements a = append(a[3:], a[:5]....). You would need to call remove two > times, which is slower and cumbersome. > > I have rather have two functions like copy and append than a dozen that I > have to learn. One of the Go Proverbs is "The bigger the interface the > weaker the abstraction." > > Greetings, Uli > On Friday, February 5, 2021 at 12:55:36 AM UTC+1 selahad...@gmail.com > wrote: > >> Hi, >> I wonder if there are any proposals for the Remove method for Slices, >> which removes an element from a Slice. >> >> Since the status of the latest generics draft is `likely accepted` and >> it'd be possible to implement this with `generics`. I believe such an >> addition to language would alleviate the need to `loop + swap + resize` >> each time, and enhance the overall readability since there is a consensus. >> >> This may seem trivial, but I want to highlight some examples from other >> langs just to further* concretize*: >> arraylist.remove(object o) => java >> list.remove(val) => python >> array.remove(at: 0) => swift >> >> I have looked for the proposals for Go 2 but couldn't find any regarding >> this issue. >> >> There are obviously more things to consider, like whether the operation >> should keep the order. >> >> I'd be very happy with your responses to this pseudo-proposal. >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/a7864041-2484-4664-9b2f-1578384defe0n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/a7864041-2484-4664-9b2f-1578384defe0n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA%3DXfu3KW5F0AspbZMX-RMkG35xMJ-hfBwcgU8cmSuQiDy57%2Bg%40mail.gmail.com.