underscore/unique.go
Ruidy 7fef1562f2
unique function (#27)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-04-12 23:32:13 +02:00

12 lines
235 B
Go

package underscore
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
}