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

slices: add Reduce function #68330

Closed
idsulik opened this issue Jul 7, 2024 · 1 comment
Closed

slices: add Reduce function #68330

idsulik opened this issue Jul 7, 2024 · 1 comment

Comments

@idsulik
Copy link

idsulik commented Jul 7, 2024

I propose a small, trivial addition to the slices package.

func Reduce[S ~[]E, E any, T any](s S, f func(T, E) T, init T) T {
	for _, v := range s {
		init = f(init, v)
	}
	return init
}

I often use similar func in other languages (js, PHP) and I think it'll be useful for GO as well.

I'm happy to contribute a PR with tests if this is a good idea.

@seankhliao
Copy link
Member

Duplicate of #61898

@seankhliao seankhliao marked this as a duplicate of #61898 Jul 7, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
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

No branches or pull requests

2 participants