Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-06 Thread Jan Mercl
On Sat, Feb 6, 2021 at 8:01 PM Axel Wagner wrote: > FTR, I think even a library function that is defined as "the equivalent of > `append(a[:i], a[j:]...)`" (for example) would provide value. Yes, but IMO a net negative value. Many people will then mindlessly just use this O(n) variant even

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-06 Thread 'Axel Wagner' via golang-nuts
FTR, I think even a library function that is defined as "the equivalent of `append(a[:i], a[j:]...)`" (for example) would provide value. That being said, I also think having this discussion now seems pointless. Any of it will clearly not happen before generics land (or are rejected), which is

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-06 Thread Jan Mercl
On Sat, Feb 6, 2021 at 5:36 PM Sean wrote: > I think there is definitely a need for a built-in "remove" function for > arrays and slice. > Everyone is writing their own implementation for this, it is both confusing > and "x = append(a[:x], b[x:])" like blablabla is not readable. Please define

[go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-06 Thread Sean
I think there is definitely a need for a built-in "*remove*" function for arrays and slice. Everyone is writing their own implementation for this, it is both confusing and "x = append(a[:x], b[x:])" like blablabla is not readable. 5 Şubat 2021 Cuma tarihinde saat 02:55:36 UTC+3 itibarıyla

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Artur Vianna
it may be useful to avoid repetition, for example if implementing stacks, you have to create the "pop(), push(), top()" before starting to code what you want. Maybe there's place for this utility functions under the "container/" package (like "container/slice"), where you could do things like:

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Jan Mercl
On Fri, Feb 5, 2021 at 3:46 PM Fernando Meyer wrote: > I understand the pragmatism behind having or not features in the language and > its standard library. But, almost all the golang projects I've worked with > implement their own utility function to remove elements from a slice, > sometimes

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Ian Lance Taylor
On Fri, Feb 5, 2021 at 6:46 AM Fernando Meyer wrote: > I understand the pragmatism behind having or not features in the language > and its standard library. But, almost all the golang projects I've worked > with implement their own utility function to remove elements from a slice, > sometimes

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Fernando Meyer
I understand the pragmatism behind having or not features in the language and its standard library. But, almost all the golang projects I've worked with implement their own utility function to remove elements from a slice, sometimes with order in place, others not. Mostly always these

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Matthew Holiday
See also this graphical cheat sheet: https://ueokande.github.io/go-slice-tricks/ On Fri, Feb 5, 2021 at 2:09 AM Brian Candler wrote: > See: https://github.com/golang/go/wiki/SliceTricks#delete > (and lots of other neat tricks there). > > There's no need to add new syntax or functions when the

[go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-05 Thread Brian Candler
See: https://github.com/golang/go/wiki/SliceTricks#delete (and lots of other neat tricks there). There's no need to add new syntax or functions when the existing ones do the job. On Thursday, 4 February 2021 at 23:55:36 UTC selahad...@gmail.com wrote: > Hi, > I wonder if there are any

Re: [go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-04 Thread Tyler Compton
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

[go-nuts] Re: Possible Go 2 proposal for built-in Remove method for Slices.

2021-02-04 Thread Uli Kunitz
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