@@ -20,9 +20,8 @@ This library heavily makes use of `reflect` package and hence will have an **imp
2020
2121### Map
2222
23- Map applies a mapper function on each element of an input and sets it in output.
24-
25- _ Primitive types_
23+ Map applies a mapper function on each element of an input and sets it in output.
24+ For more [ docs] ( https://godoc.org/github.com/thecasualcoder/godash#Map ) .
2625
2726``` go
2827func main () {
@@ -37,8 +36,6 @@ func main() {
3736}
3837```
3938
40- _ Struct type_
41-
4239``` go
4340type Person struct {
4441 Name string
@@ -62,7 +59,8 @@ func main() {
6259
6360### Filter
6461
65- Filter out elements that fail the predicate
62+ Filter out elements that fail the predicate.
63+ For more [ docs] ( https://godoc.org/github.com/thecasualcoder/godash#Filter ) .
6664
6765``` go
6866func main () {
@@ -95,31 +93,38 @@ func main() {
9593
9694### Reduce
9795
98- Reduce reduces the given collection using given reduce function
99-
100- _ Primitive types_
96+ Reduce can accept a reducer and apply the reducer on each element of the input slice while providing an accumulator to save the reduce output
97+ For more [ docs] ( https://godoc.org/github.com/thecasualcoder/godash#Reduce ) .
10198
10299``` go
103100func main () {
104- input := []int {1 , 2 , 3 , 4 , 5 }
105- var output int
106-
107- godash.Reduce (input, &output, func (sum, element int ) int {
108- return sum + element
101+ input := []string {" count" , " words" , " and" , " print" , " words" , " count" }
102+ accumulator := map [string ]int {}
103+
104+ _ = godash.Reduce (input, &accumulator, func (acc map [string ]int , element string ) map [string ]int {
105+ if _ , present := acc[element]; present {
106+ acc[element] = acc[element] + 1
107+ } else {
108+ acc[element] = 1
109+ }
110+ return acc
109111 })
110112
111- fmt.Println (output) // prints 15
112- }
113- ```
113+ bytes , _ := json.MarshalIndent (accumulator, " " , " " )
114+ fmt.Println (string (bytes))
114115
115- _ Struct type_
116+ // Output:
117+ // {
118+ // "and": 1,
119+ // "count": 2,
120+ // "print": 1,
121+ // "words": 2
122+ // }
116123
117- ``` go
118- type Person struct {
119- Name string
120- Age Int
121124}
125+ ```
122126
127+ ``` go
123128func main () {
124129 input := []Person{
125130 {Name: " John" , Age: 22 },
0 commit comments