lo icon indicating copy to clipboard operation
lo copied to clipboard

Use variadic parameters in Min and Max

Open hanlins opened this issue 3 years ago • 2 comments

Greetings and thanks to this amazing project! I used Min and Max quite frequently and I found it annoying that I have to put the values into an array even when I got two elements. From my previous exp with c++, variadic parameters is used in max signature so developer can enter any number of parameters without creating an array/slice on themselves (see ref).

The usage for Max could be:

max := lo.Max(1, 2, 3)

If developer wants to find the max element from an array, they can do:

array := []int{1, 2, 3}
max := lo.Max(array...)

hanlins avatar Mar 20 '22 08:03 hanlins

This is a great suggestion!

NilsJPWerner avatar Apr 12 '22 22:04 NilsJPWerner

It might be worth replacing the Zip2 through Zip9 functions with a single variadic version as well.

NilsJPWerner avatar Apr 12 '22 22:04 NilsJPWerner