Where a is the slice, and i is the index of the element you want to delete:
a = append(a[:i], a[i+1:]...)
... is the syntax for variational arguments in Go.
Basically, when you define a function, it puts all the arguments that you pass into one fragment of this type. By doing this, you can pass as many arguments as you want (for example, fmt.Println can take as many arguments as you want).
Now, when the function is called , ... does the opposite: it unpacks the slice and passes them as separate arguments to the variable function.
So what this line does:
a = append(a[:0], a[1:]...)
essentially:
a = append(a[:0], a[1], a[2])
Now you may be wondering why not just do
a = append(a[:1]...)
Well, append function definition is equal
func append(slice []Type, elems ...Type) []Type
So, the first argument should be a slice of the correct type, the second argument should be a variable, so we pass an empty fragment, and then unpack the rest of the slice to fill in the arguments.
dave Jul 29 '14 at 21:47 2014-07-29 21:47
source share