Loading…
0+ curated questions with the same answer shape every time: quick recap, deep dive, pitfalls, and follow-ups. Coverage includes .
Generics arrived in Go 1.18 and changed how you write reusable library code. This module covers type parameters (the square-bracket syntax func Map[T, U any](s []T, f func(T) U) []U), type constraints (interface-based constraints, the comparable built-in for maps and ==, the golang.org/x/exp/constraints package for Ordered), type inference so callers rarely need to spell out the type argument, and the critical design question that comes up in every generics interview: when do generics actually help and when does an interface do the job better? Go generics deliberately do not support operator overloading or runtime dispatch — these omissions are intentional and interviewers probe whether you understand the trade-offs. Every answer includes a real use case from production code (generic Result[T] type, Map/Filter/Reduce pipeline) and the anti-pattern it replaces.
Full catalog
Topics are ordered for learning. Within each topic, rows are numbered 1–0 globally so you always know where you are. Collapse topics if you want a lighter view — use Expand all when you need the full list again.
Numbers 1–0 follow the order we recommend — click any row to open the full answer, or use the sticky Next link at the bottom of each page to go Q1 → Q0.