mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
10 lines
322 B
Go
10 lines
322 B
Go
package underscore
|
|
|
|
// Reduce combine a list of values into a single value.
|
|
// acc is the initial state, and each successive step of it should be returned by the reduction function.
|
|
func Reduce[T, P any](values []T, reduction func(T, P) P, acc P) P {
|
|
for _, v := range values {
|
|
acc = reduction(v, acc)
|
|
}
|
|
return acc
|
|
}
|