underscore/unique.go
Ruidy fbf58eff42
Refresh documentation (#39)
* minor documentation fixes

* fix Hugo warnings

* add openssf badge
2024-12-03 09:29:53 +01:00

13 lines
300 B
Go

package underscore
// Unique returns a slice of unique values from the given slice.
func Unique[T comparable](values []T) (uniques []T) {
seen := make(map[T]bool, 0)
for _, v := range values {
if _, ok := seen[v]; !ok {
uniques = append(uniques, v)
seen[v] = true
}
}
return uniques
}