src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

unique.go (219B)


      1 package unique
      2 
      3 func Unique[T comparable](s []T) (r []T) {
      4 	var unique = map[T]struct{}{}
      5 
      6 	for _, v := range s {
      7 		if _, exists := unique[v]; !exists {
      8 			unique[v] = struct{}{}
      9 			r = append(r, v)
     10 		}
     11 	}
     12 
     13 	return r
     14 }