feat: add ReduceConcurrent

This commit is contained in:
dudaodong committed 2024-08-15 17:48:26 +08:00
1 parent 305847993c
commit c0b200f846
5 files changed
+165 -4

No files matched your search

+12
View File
@@ -527,6 +527,18 @@ func ExampleReduce() {
// 6
}
func ExampleReduceConcurrent() {
nums := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
result := ReduceConcurrent(nums, 0, func(_ int, item, agg int) int {
return agg + item
}, 1)
fmt.Println(result)
// Output:
// 55
}
func ExampleReduceBy() {
result1 := ReduceBy([]int{1, 2, 3, 4}, 0, func(_ int, item int, agg int) int {
return agg + item