~/talk

Generics!

Talkat GopherCon 2021 · 2021-12-05..12-08· [go]
slides:none on file

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

  1. 0:00Start
  2. 2:10Type parameter lists
  3. 3:17Instantiation
  4. 5:06The types of value parameters
  5. 5:27The types of type parameters
  6. 7:02Interfaces define method sets
  7. 7:27Interfaces also define type sets
  8. 8:20A type set with three types
  9. 8:50constraints.Ordered
  10. 10:43Constraint literals
  11. 12:33Calling min without type inference
  12. 15:20Scale a slice of any integer type
  13. 17:22Scale a Point
  14. 21:30When are type parameters useful?
  15. 23:08Tree is a generic binary tree.
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.