Generics in Go

Generics in Go

42mIntermediate2023-01-03

Authors

Anna-Katharina Wickert

Anna-Katharina Wickert

Developer, Speaker

Course details

Repeating code by writing boilerplate code over and over again can often lead to mistake-ridden, messy code. In this course, Anna-Katharina Wickert shows you how to use generics in Go to write cleaner and easier-to-read code. Anna-Katharina shows how you can use generics—long on developers’ wishlists and introduced in Go 1.18—to write functions and types that work with a set of types instead of one concrete type. She covers type parameters, typesets, and type inference, and puts it all into practice with examples and looks into new packages shipped along with generics.

Skills covered

GoProgramming FoundationsGoogleProgramming LanguagesSoftware DevelopmentOne-Off

Concepts

Introduction

  • Generics in Go 1.18
  • What you should know

Type Parameters

  • Type parameter 101
  • Instantiation of generic functions
  • Challenge - Type parameter with composite type
  • Solution - Type parameter with composite type

Type Sets

  • Type set 101
  • Define type sets
  • Experimental package - Constraints

Type Inference

  • Function argument type inference
  • Constraint type inference

Generics in Practice

  • Best practice for usage
  • Experimental package - Slices
  • Experimental package - Maps
  • Known limitations

Conclusion

  • Next steps
40,000 Toman