Go Generics Laboratory
Design decisions
- Start from constraints.
- Keep APIs readable.
- Favor narrow, meaningful type sets.
~ and aliases
~intsupportstype MyInt int- avoids forcing cast-heavy call sites.
Return types
func F[S ~[]T, T any](...) Spreserves typed slices.- helps ergonomic libraries with named collection types.
Practical checklist
- explicit order of first-seen items
- deterministic handling of empty inputs
- predictable behavior when key function is missing
1 / 1