Go Generics Laboratory
Trace identity, preserve first-seen order, and retain the caller's named slice type.
1 / 5
Trace identity, preserve first-seen order, and retain the caller's named slice type.
S ~[]T: caller's slice type. T any: arbitrary row value. K comparable: map key.
A row can contain a slice and still deduplicate by an integer ID.
(4,Ada), (2,Lin), (4,Bea), (3,Kai) by ID → (4,Ada), (2,Lin), (3,Kai).
Map membership decides whether to append; map iteration must not determine output order.
Empty input or nil key function returns nil S. Returning []T instead of S loses the defined slice return type. A copied struct may still share pointer-backed data: generics do not deep-copy it.
Dedupe the same rows by first letter of Name, then add (9,Ari). Explain the changed output before implementing. Design last-value retention at first-key positions as a separate variation.