game-crawler/utils/unique.go
2024-09-24 18:17:11 +08:00

16 lines
240 B
Go

package utils
func Unique[T comparable](slice []T) []T {
seen := make(map[T]struct{})
var result []T
for _, v := range slice {
if _, ok := seen[v]; !ok {
seen[v] = struct{}{}
result = append(result, v)
}
}
return result
}