Go Generics Laboratory

Design decisions

  • Start from constraints.
  • Keep APIs readable.
  • Favor narrow, meaningful type sets.

~ and aliases

  • ~int supports type MyInt int
  • avoids forcing cast-heavy call sites.

Return types

  • func F[S ~[]T, T any](...) S preserves 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
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.