Files
LocalAGI/pkg/xstrings/uniq.go
Ettore Di Giacinto fa12dba7c2 Better paragraph splitting
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2025-03-25 22:28:08 +01:00

16 lines
297 B
Go

package xstrings
type Comparable interface{ ~int | ~int64 | ~string }
func UniqueSlice[T Comparable](s []T) []T {
keys := make(map[T]bool)
list := []T{}
for _, entry := range s {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}