aboutsummaryrefslogblamecommitdiff
path: root/reduce.go
blob: 46c186a7635a83def25af3743c4863dbd0913f9d (plain) (tree)
1
2
3
4
5
6
7
8







                                                                                                       
package collection

func Reduce[T any, R any](collection []T, cb func(previous R, current T, idx int) R, accumulator R) R {
	for i, v := range collection {
		accumulator = cb(accumulator, v, i)
	}
	return accumulator
}