Compact Adjacent Slice Values with slices.CompactFunc in Go
slices.CompactFunc removes repeated values only when equivalent elements are adjacent. That detail makes it distinct from general deduplication: the function operates on runs, keeps the first element from each run, and leaves separated matches alone. The custom equality function also allows compaction for structs and for equivalence rules that differ from Go’s == operator. Compaction is based on neighboring values The function has this signature: func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S For each run in which neighboring elements satisfy eq, the first element remains in the result. Consider case-insensitive string comparison: