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.
Comment From: seankhliao
Duplicate of #61898