Skip to Content
Learning Functional Programming in Go
book

Learning Functional Programming in Go

by Lex Sheehan
November 2017
Intermediate to advanced
670 pages
17h 35m
English
Packt Publishing
Content preview from Learning Functional Programming in Go

No Generics results in a lot of boilerplate code 

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 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781787281394Supplemental Content