Back to Lo

Core Reduce

docs/data/core-reduce.md

1.53.0254 B
Original Source

Reduces a collection to a single value by accumulating results of an accumulator function. Each call receives the previous result value.

go
sum := lo.Reduce([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
    return agg + item
}, 0)
// 10