I encountered weird behaviour in go code today: when I append elements to slice in loop and then try to create new slices based on the res
elements
slice
slices
There is also a little bit simpler way to implement copyAndAppend function:
copyAndAppend
func copyAndAppend(source []string, items ...string) []string { l := len(source) return append(source[:l:l], items...) }
Here we just make sure that source has no available capacity and so copying is forced.