Go theorytheory 0/50 · 0%
Abstraction · medium

30. Generics in Go

Type parameters since Go 1.18.

Functions and types can take type parameters with constraints, e.g. `func Map[T, U any](s []T, f func(T) U) []U`. Constraints are interfaces listing methods or type sets. Use generics for genuinely reusable containers and algorithms, not to replace clear concrete code.

Check your understanding

  1. 1. Constraints are expressed as…

  2. 2. The loosest constraint is…