diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-13 20:16:46 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-13 21:52:30 -0600 |
commit | db7047c394edbcc713accda2a15f201a5b400ef7 (patch) | |
tree | 0b8fb9c1b4176af762422197cca721145cda91a6 /lib/slices | |
parent | 166e51d3a6f81834cc89aec36015f05f350be31e (diff) |
Misc tidy up
Diffstat (limited to 'lib/slices')
-rw-r--r-- | lib/slices/sliceutil.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/slices/sliceutil.go b/lib/slices/sliceutil.go index 392514f..faaffcb 100644 --- a/lib/slices/sliceutil.go +++ b/lib/slices/sliceutil.go @@ -48,18 +48,24 @@ func Reverse[T any](slice []T) { } } -func Max[T constraints.Ordered](a, b T) T { - if a > b { - return a +func Max[T constraints.Ordered](a T, rest ...T) T { + ret := a + for _, b := range rest { + if b > a { + ret = b + } } - return b + return ret } -func Min[T constraints.Ordered](a, b T) T { - if a < b { - return a +func Min[T constraints.Ordered](a T, rest ...T) T { + ret := a + for _, b := range rest { + if b < a { + ret = b + } } - return b + return ret } func Sort[T constraints.Ordered](slice []T) { |