collection/reduce.go
Alexander Kiryukhin 9cd6b0fca8
initial
2022-04-07 21:36:40 +03:00

9 lines
219 B
Go

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
}