var list = []func(*someType) error {
...
}
I am new to Go and I am trying to understand what does the syntax mean ? Is the return of function an array?
var list = []func(*someType) error {
...
}
I am new to Go and I am trying to understand what does the syntax mean ? Is the return of function an array?
This declares and initializes a variable list
as a slice whose elements are functions with signature func(*someType) error
.
Slices in Go are convenient mechanisms for representing sequences of data of a particular type. They have type []T
for any element type T
(but remember Go does not have generics). A slice is defined only by the type of the items it contains; its length is not part of its type definition and can change at runtime. (Arrays in Go, by contrast, are of fixed length - their type is [N]T
for length N
and element type T
).
Under the surface, a slice consists of a backing array, a length of the current data and a capacity. The runtime manages the memory allocation of the array to accommodate all data in the slice.