March 2020
Intermediate to advanced
406 pages
8h 39m
English
Go originally had a vector implementation, but this was removed very early on in the language development (October 11, 2011). It was deemed that slices are better (as was the title of the pull request) and slices became the de facto vector implementation in Go. We can implement a slice as follows:
sliceExample := []string{"slices", "are", "cool", "in", "go"}
Slices are beneficial because, like vectors in the STL, they can grow or shrink based on addition or deletion. In our example, we create a slice, append a value to the slice, and remove a value from the slice, as illustrated in the following code:
package mainimport "fmt"// Remove i indexed item in slicefunc remove(s []string, i int) []string { copy(s[i:], s[i+1:]) return s[:len(s)-1] ...Read now
Unlock full access