A slice is a dynamically sized, flexible view into the elements of an
array. Apparently they are much more common than arrays. Initialization
is pretty straight forward:
Slices are like references. Change something in the slice and the
array it references also changes
Slices can contain any type, including other slices:
Slice literals
A slice literal is like an array, but without the length, so we add more
stuff to it later
Slice defaults
You can omit high and low bounds. As one would expect these default to 0
and slice length respectively
Slice length and capacity
One can lookup slice length (length of the slice) and capacity (length
of the array the slice references)
Nil slices
Empty slices are equal to nil. Maybe that’s a good idea, maybe it
isn’t. Typing this i’m too tired to give rational input to this
philosophical quagmire.
Make
Slices can be created with the make function, this way you can treat
them like arrays that we know and love.
Append
New elements can be added to a slice with the
append function
Range
You can iterate over slices with range
Index or value can be skipped by using _. In case you only want the
index, just omit the second variable entirely: