@@ -30,7 +30,7 @@ func TestForEachEmpty(t *testing.T) {
30
30
}
31
31
32
32
func ExampleForEach2 () {
33
- it .ForEach2 (it . Enumerate ( slices .Values ([]int {1 , 2 , 3 }) ), func (index int , number int ) {
33
+ it .ForEach2 (slices .All ([]int {1 , 2 , 3 }), func (index int , number int ) {
34
34
fmt .Println (index , number )
35
35
})
36
36
// Output:
@@ -59,7 +59,7 @@ func TestReduceEmpty(t *testing.T) {
59
59
}
60
60
61
61
func ExampleReduce2 () {
62
- fmt .Println (it .Reduce2 (it . Enumerate ( slices .Values ([]int {1 , 2 , 3 }) ), func (i , a , b int ) int {
62
+ fmt .Println (it .Reduce2 (slices .All ([]int {1 , 2 , 3 }), func (i , a , b int ) int {
63
63
return i + 1
64
64
}, 0 ))
65
65
@@ -115,7 +115,7 @@ func ExampleFind_notFound() {
115
115
}
116
116
117
117
func ExampleFind2 () {
118
- index , value , ok := it .Find2 (it . Enumerate ( slices .Values ([]int {1 , 2 , 3 }) ), func (i , v int ) bool {
118
+ index , value , ok := it .Find2 (slices .All ([]int {1 , 2 , 3 }), func (i , v int ) bool {
119
119
return i == 2
120
120
})
121
121
fmt .Println (index , value , ok )
@@ -124,24 +124,46 @@ func ExampleFind2() {
124
124
}
125
125
126
126
func ExampleFind2_notFound () {
127
- index , value , ok := it .Find2 (it . Enumerate ( slices .Values ([]int {1 , 2 , 3 }) ), func (i , v int ) bool {
127
+ index , value , ok := it .Find2 (slices .All ([]int {1 , 2 , 3 }), func (i , v int ) bool {
128
128
return i == 4
129
129
})
130
130
131
131
fmt .Println (index , value , ok )
132
132
// Output: 0 0 false
133
133
}
134
134
135
- func ExampleCollectErr () {
136
- data := strings .NewReader ("one\n two\n three\n " )
137
- lines , err := it .CollectErr (it .LinesString (data ))
135
+ func ExampleCollect2 () {
136
+ indicies , values := it .Collect2 (slices .All ([]int {1 , 2 , 3 }))
137
+ fmt .Println (values )
138
+ fmt .Println (indicies )
139
+
140
+ // Output:
141
+ // [1 2 3]
142
+ // [0 1 2]
143
+ }
144
+
145
+ func ExampleTryCollect () {
146
+ text := strings .NewReader ("one\n two\n three\n " )
147
+
148
+ lines , err := it .TryCollect (it .LinesString (text ))
138
149
fmt .Println (err )
139
150
fmt .Println (lines )
151
+
140
152
// Output:
141
153
// <nil>
142
154
// [one two three]
143
155
}
144
156
157
+ func TestTryCollectError (t * testing.T ) {
158
+ t .Parallel ()
159
+
160
+ text := new (failSecondTime )
161
+ lines , err := it .TryCollect (it .LinesString (text ))
162
+
163
+ assert .Equal (t , err .Error (), "read error" )
164
+ assert .SliceEqual (t , lines , []string {"o" })
165
+ }
166
+
145
167
func ExampleLen () {
146
168
fmt .Println (it .Len (slices .Values ([]int {1 , 2 , 3 })))
147
169
@@ -155,7 +177,7 @@ func TestLenEmpty(t *testing.T) {
155
177
}
156
178
157
179
func ExampleLen2 () {
158
- fmt .Println (it .Len2 (it . Enumerate ( slices .Values ([]int {1 , 2 , 3 }) )))
180
+ fmt .Println (it .Len2 (slices .All ([]int {1 , 2 , 3 })))
159
181
160
182
// Output: 3
161
183
}
0 commit comments