mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
* change documentation theme and structure * add config files * fix links * add build doc command Co-authored-by: Ruidy <rnemausat@newstore.com>
22 lines
447 B
Markdown
22 lines
447 B
Markdown
---
|
|
title: "Reduce"
|
|
date: 2022-03-21T13:33:52-04:00
|
|
---
|
|
|
|
`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.
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func main() {
|
|
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
sum := func(n, acc int) int { return n + acc }
|
|
fmt.Println(u.Reduce(nums, sum, 0)) // 45
|
|
}
|
|
```
|