From 7ddb05602caeb9f55946e70a600533aeb908098d Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 1 Jan 2022 14:21:05 -0400 Subject: [PATCH] refactor: use contraints --- contains.go | 4 +++- max.go | 4 +++- min.go | 4 +++- types.go | 5 ----- 4 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 types.go 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 -}