Skip to content

Commit

Permalink
panic if unique takes in pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Jan 21, 2025
1 parent 4020141 commit 1ccbe7d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions utils/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ func AnyOf[T comparable](e T, values ...T) bool {
return false
}

// Unique returns a new slice with duplicates removed
// Unique returns a new slice with duplicates removed.
// Panics if the slice contains pointer types.
func Unique[T comparable](slice []T) []T {
if len(slice) == 0 {
return slice
}

// do not support unique on pointer types, just return the slice as it is
if reflect.TypeOf(slice[0]).Kind() == reflect.Ptr {
return slice
panic("Unique does not support pointer types")
}

result := make([]T, 0, len(slice))
Expand Down

0 comments on commit 1ccbe7d

Please sign in to comment.