Skip to content

Commit 78bc879

Browse files
committed
Update README
Signed-off-by: Dinesh <dineshudt17@gmail.com>
1 parent 01cfa66 commit 78bc879

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This library heavily makes use of `reflect` package and hence will have an **imp
1111

1212
1. [Map](#Map)
1313
2. [Filter](#Filter)
14+
3. [Reduce](#Reduce)
1415

1516
## Usages
1617

@@ -88,3 +89,45 @@ func main() {
8889
fmt.Println(output) // prints {Doe 30}
8990
}
9091
```
92+
93+
### Reduce
94+
95+
Reduce reduces the given collection using given reduce function
96+
97+
_Primitive types_
98+
99+
```go
100+
func main() {
101+
input := []int{1, 2, 3, 4, 5}
102+
var output int
103+
104+
godash.Reduce(input, &output, func(sum, element int) int {
105+
return sum + element
106+
})
107+
108+
fmt.Println(output) // prints 15
109+
}
110+
```
111+
112+
_Struct type_
113+
114+
```go
115+
type Person struct {
116+
Name string
117+
Age Int
118+
}
119+
120+
func main() {
121+
input := []Person{
122+
{Name: "John", Age: 22},
123+
{Name: "Doe", Age: 23},
124+
}
125+
var output int
126+
127+
godash.Reduce(input, &output, func(sum int, person Person) int {
128+
return sum + person.Age
129+
})
130+
131+
fmt.Println(output) // prints 45
132+
}
133+
```

0 commit comments

Comments
 (0)