@@ -52,3 +52,164 @@ func ExampleUniqBy() {
52
52
}))
53
53
// Output: [{1 foo} {2 foobar} {3 foo}]
54
54
}
55
+
56
+ func ExampleGroupBy () {
57
+ type User struct {
58
+ id int
59
+ name string
60
+ }
61
+ users := []User {
62
+ {1 , "foo" },
63
+ {2 , "foobar" },
64
+ {3 , "foobar" },
65
+ {4 , "foo" },
66
+ {5 , "bar" },
67
+ }
68
+ fmt .Println (godash .GroupBy (users , func (u User ) string {
69
+ return u .name
70
+ }))
71
+ // Output: map[bar:[{5 bar}] foo:[{1 foo} {4 foo}] foobar:[{2 foobar} {3 foobar}]]
72
+ }
73
+
74
+ func ExampleChunk () {
75
+ integers := []int {0 , 1 , 1 , 3 , 2 , 1 , 1 , 0 }
76
+ fmt .Println (godash .Chunk (integers , 3 ))
77
+ // Output: [[0 1 1] [3 2 1] [1 0]]
78
+ }
79
+
80
+ func ExamplePartitionBy () {
81
+ type User struct {
82
+ id int
83
+ name string
84
+ }
85
+ users := []User {
86
+ {1 , "foo" },
87
+ {2 , "foobar" },
88
+ {3 , "foobar" },
89
+ {4 , "foo" },
90
+ {5 , "bar" },
91
+ }
92
+ fmt .Println (godash .PartitionBy (users , func (u User ) string {
93
+ return u .name
94
+ }))
95
+ // Output: [[{1 foo} {4 foo}] [{2 foobar} {3 foobar}] [{5 bar}]]
96
+ }
97
+
98
+ func ExampleFlatten () {
99
+ integers := [][]int {
100
+ {1 , 2 , 5 , 10 },
101
+ {9 , 8 , 1 },
102
+ {0 },
103
+ {42 , 3 },
104
+ }
105
+ fmt .Println (godash .Flatten (integers ))
106
+ // Output: [1 2 5 10 9 8 1 0 42 3]
107
+ }
108
+
109
+ func ExampleKeyBy () {
110
+ type User struct {
111
+ id int
112
+ name string
113
+ }
114
+ users := []User {
115
+ {1 , "foo" },
116
+ {2 , "foobar" },
117
+ {3 , "foobar" },
118
+ {4 , "foo" },
119
+ {5 , "bar" },
120
+ }
121
+ fmt .Println (godash .KeyBy (users , func (u User ) int {
122
+ return u .id
123
+ }))
124
+ // Output: map[1:{1 foo} 2:{2 foobar} 3:{3 foobar} 4:{4 foo} 5:{5 bar}]
125
+ }
126
+
127
+ func ExampleKeys () {
128
+ m := map [int ]string {
129
+ 1 : "foo" ,
130
+ 2 : "bar" ,
131
+ 3 : "baz" ,
132
+ }
133
+ fmt .Println (godash .Keys (m ))
134
+ // Output: [1 2 3]
135
+ }
136
+
137
+ func ExampleValues () {
138
+ m := map [int ]string {
139
+ 1 : "foo" ,
140
+ 2 : "bar" ,
141
+ 3 : "baz" ,
142
+ }
143
+ fmt .Println (godash .Values (m ))
144
+ // Output: [foo bar baz]
145
+ }
146
+
147
+ func ExampleSum () {
148
+ numbers := []float32 {1 , 5 , 2 , 3.2 , 42 }
149
+ fmt .Println (godash .Sum (numbers ))
150
+ // Output: 53.2
151
+ }
152
+
153
+ func ExampleSumBy () {
154
+ type User struct {
155
+ name string
156
+ age int
157
+ }
158
+ users := []User {
159
+ {"foo" , 20 },
160
+ {"bar" , 25 },
161
+ {"baz" , 40 },
162
+ }
163
+ fmt .Println (godash .SumBy (users , func (u User ) int {
164
+ return u .age
165
+ }))
166
+ // Output: 85
167
+ }
168
+
169
+ func ExampleEveryBy () {
170
+ type User struct {
171
+ name string
172
+ age int
173
+ }
174
+ users := []User {
175
+ {"foo" , 20 },
176
+ {"bar" , 25 },
177
+ {"baz" , 40 },
178
+ }
179
+ fmt .Println (godash .EveryBy (users , func (u User ) bool {
180
+ return u .age >= 20
181
+ }))
182
+ // Output: true
183
+ }
184
+
185
+ func ExampleNoneBy () {
186
+ type User struct {
187
+ name string
188
+ age int
189
+ }
190
+ users := []User {
191
+ {"foo" , 20 },
192
+ {"bar" , 25 },
193
+ {"baz" , 40 },
194
+ }
195
+ fmt .Println (godash .NoneBy (users , func (u User ) bool {
196
+ return u .age > 40
197
+ }))
198
+ // Output: true
199
+ }
200
+
201
+ func ExampleFind () {
202
+ type User struct {
203
+ name string
204
+ age int
205
+ }
206
+ users := []User {
207
+ {"foo" , 20 },
208
+ {"bar" , 25 },
209
+ {"baz" , 40 },
210
+ }
211
+ fmt .Println (godash .Find (users , func (u User ) bool {
212
+ return u .age > 24
213
+ }))
214
+ // Output: {bar 25} true
215
+ }
0 commit comments