diff --git a/contains.go b/contains.go index e4e49e6..55cd559 100644 --- a/contains.go +++ b/contains.go @@ -1,7 +1,9 @@ package underscore +import "constraints" + // Contains returns true if the value is present in the slice -func Contains[T numbers](values []T, value T) bool { +func Contains[T constraints.Ordered](values []T, value T) bool { for _, v := range values { if v == value { return true diff --git a/max.go b/max.go index 440cbbe..b1e92ac 100644 --- a/max.go +++ b/max.go @@ -1,9 +1,11 @@ package underscore +import "constraints" + // Max returns the maximum value in the slice. // This function can currently only compare numbers reliably. // This function uses operator <. -func Max[T numbers](values []T) T { +func Max[T constraints.Ordered](values []T) T { max := values[0] for _, v := range values { if v > max { diff --git a/min.go b/min.go index a2883ea..ce518fa 100644 --- a/min.go +++ b/min.go @@ -1,9 +1,11 @@ package underscore +import "constraints" + // Min returns the minimum value in the slice. // This function can currently only compare numbers reliably. // This function uses operator <. -func Min[T numbers](values []T) T { +func Min[T constraints.Ordered](values []T) T { min := values[0] for _, v := range values { if v < min { diff --git a/types.go b/types.go deleted file mode 100644 index 50c6345..0000000 --- a/types.go +++ /dev/null @@ -1,5 +0,0 @@ -package underscore - -type numbers interface { - int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 -}