November 2017
Intermediate to advanced
670 pages
17h 35m
English
Without support for generics, when we implement a list function, we must implement it for each type our application requires. It's a lot of repetitive, boilerplate code. For example, if we must implement a Sum function for int8, int32, float64, and complex128, this is what it might look like:
package mainimport ( "fmt")func int8Sum(list []int8) (int8) { var result int8 = 0 for x := 0; x < len(list); x++ { result += list[x] } return result}func int32Sum(list []int32) (int32) { var result int32 = 0 for x := 0; x < len(list); x++ { result += list[x] } return result}func float64Sum(list []float64) (float64) { var result float64 = 0 for x := 0; x < len(list); x++ { result += list[x] } return