Generics!
summary
Go 1.18 adds type parameters for functions and types, interfaces as type sets with unions and the tilde T syntax to allow underlying-type matching, a new constraints package (e.g. constraints.Ordered), and type inference including constraint type inference. Examples: a generic mean and a generic binary tree; a scale example shows adding a type parameter S preserves the concrete named slice type (point) on return. Guidance: use generics for slices/maps/channels and reusable data structures, prefer functions for comparisons, but keep interfaces or reflection when behavior varies by type.
AI-written summary · about
chapters (15)
- 0:00Start
- 2:10Type parameter lists
- 3:17Instantiation
- 5:06The types of value parameters
- 5:27The types of type parameters
- 7:02Interfaces define method sets
- 7:27Interfaces also define type sets
- 8:20A type set with three types
- 8:50constraints.Ordered
- 10:43Constraint literals
- 12:33Calling min without type inference
- 15:20Scale a slice of any integer type
- 17:22Scale a Point
- 21:30When are type parameters useful?
- 23:08Tree is a generic binary tree.








