pcgamedb/utils/unique.go

16 lines
240 B
Go
Raw Normal View History

2024-09-24 06:17:11 -04:00
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
}