16 lines
240 B
Go
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
|
||
|
}
|