Curriculum Collections
module 2 of 7
Collections
Arrays, slices, maps, and the for-range loop. The translation pattern still works but the wrinkles deepen: slices are views, map iteration is unordered, and range gives you index+value.
themes
2.1
Arrays vs slices
Go has fixed-size arrays ([N]T) and dynamically-sized
slices ([]T). You almost always want slices. A slice is a
view over a backing array — three machine words: pointer…
for i, v := range collection is the workhorse. Over a slice you
get (index, value). Over a map you get (key, value). Over a
string you get (byteIndex, rune). Over a channel…