-
-
Notifications
You must be signed in to change notification settings - Fork 855
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Implement Min/Max as variadic functions #224
Comments
Hi @dergus, For the current available functions, that'd be a breaking change. See an example here. While a variadic parameter may take a slice, you're still required to add We could still consider a second set of functions with the variadic parameters. @samber, if you think that makes sense, I would like to work on that as part of hacktoberfest. |
Hi, I see |
I implemented a version in more convenient way, I do not agree to change the interface, because the interface of the base library once opened to change will cause a lot of dissatisfaction. func MaxN[T constraints.Ordered](items ...T) T {
return Max(items)
}
func MinN[T constraints.Ordered](items ...T) T {
return Min(items)
} If you @samber looks good, please approve it. |
In Go 1.21, built-in min and max functions were introduced, allowing developers to determine the minimum and maximum values among a set of comparable elements without the need for external libraries. I don't think this needs to be implemented as the language already provides a built-in variadic approach |
Having
Min
/Max
functions take a slice as an argument is a bit inconvenient when you have just two variables because then you have to create an array out of them just for calling Min/Max functions.And with variadic version you still could provide a slice if you wished by using the
...
operator.The text was updated successfully, but these errors were encountered: