Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Min/Max as variadic functions #224

Open
dergus opened this issue Sep 24, 2022 · 4 comments · May be fixed by #234
Open

Implement Min/Max as variadic functions #224

dergus opened this issue Sep 24, 2022 · 4 comments · May be fixed by #234

Comments

@dergus
Copy link
Contributor

dergus commented Sep 24, 2022

HavingMin/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.

@rkperes
Copy link

rkperes commented Oct 8, 2022

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 ... after the slice argument, making it a breaking change.

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.

@dergus
Copy link
Contributor Author

dergus commented Oct 9, 2022

Hi, I see
That's also an option. I have a pr for this but I can reimplement as a separate set of functions

dergus added a commit to dergus/lo that referenced this issue Oct 9, 2022
@dergus dergus linked a pull request Oct 9, 2022 that will close this issue
@samber
Copy link
Owner

samber commented Oct 11, 2022

Hi @dergus & @rkperes

I agree, but I am reluctant to any breaking change. I will let this issue+PR open until v2.0.0.

@dashjay
Copy link

dashjay commented Nov 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants