git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/slicesx/unique.go (about) 1 package slicesx 2 3 func Unique[T comparable](input []T) []T { 4 inResult := make(map[T]bool, len(input)) 5 var result []T 6 7 for _, elem := range input { 8 if _, ok := inResult[elem]; !ok { 9 inResult[elem] = true 10 result = append(result, elem) 11 } 12 } 13 14 return result 15 }