Home / Go / slice tricks edit

From https://code.google.com/p/go-wiki/wiki/SliceTricks

AppendVector: a = append(a, b...)

Copy: b = make([]T, len(a))
copy(b, a)

Cut: a = append(a[:i], a[j:]...)

Delete: a = append(a[:i], a[i+1:]...)
// or
a = a[:i+copy(a[i:], a[i+1:])]

Delete without preserving order: a[i], a = a[len(a)-1], a[:len(a)-1]

github.com/bradfitz/slice
func Sort(slice interface{}, less func(i, j int) bool)
Go to index of articles.

Share on