@@ -18,6 +18,7 @@ package reflect
18
18
import (
19
19
"internal/abi"
20
20
"internal/goarch"
21
+ "iter"
21
22
"runtime"
22
23
"strconv"
23
24
"sync"
@@ -64,6 +65,10 @@ type Type interface {
64
65
// This may make the executable binary larger but will not affect execution time.
65
66
Method (int ) Method
66
67
68
+ // Methods returns an iterator over each method in the type's method set. The sequence is
69
+ // equivalent to calling Method successively for each index i in the range [0, NumMethod()).
70
+ Methods () iter.Seq [Method ]
71
+
67
72
// MethodByName returns the method with that name in the type's
68
73
// method set and a boolean indicating if the method was found.
69
74
//
@@ -172,6 +177,11 @@ type Type interface {
172
177
// It panics if i is not in the range [0, NumField()).
173
178
Field (i int ) StructField
174
179
180
+ // Fields returns an iterator over each struct field for struct type t. The sequence is
181
+ // equivalent to calling Field successively for each index i in the range [0, NumField()).
182
+ // It panics if the type's Kind is not Struct.
183
+ Fields () iter.Seq [StructField ]
184
+
175
185
// FieldByIndex returns the nested field corresponding
176
186
// to the index sequence. It is equivalent to calling Field
177
187
// successively for each index i.
@@ -208,6 +218,11 @@ type Type interface {
208
218
// It panics if i is not in the range [0, NumIn()).
209
219
In (i int ) Type
210
220
221
+ // Ins returns an iterator over each input parameter of function type t. The sequence
222
+ // is equivalent to calling In successively for each index i in the range [0, NumIn()).
223
+ // It panics if the type's Kind is not Func.
224
+ Ins () iter.Seq [Type ]
225
+
211
226
// Key returns a map type's key type.
212
227
// It panics if the type's Kind is not Map.
213
228
Key () Type
@@ -233,6 +248,11 @@ type Type interface {
233
248
// It panics if i is not in the range [0, NumOut()).
234
249
Out (i int ) Type
235
250
251
+ // Outs returns an iterator over each output parameter of function type t. The sequence
252
+ // is equivalent to calling Out successively for each index i in the range [0, NumOut()).
253
+ // It panics if the type's Kind is not Func.
254
+ Outs () iter.Seq [Type ]
255
+
236
256
// OverflowComplex reports whether the complex128 x cannot be represented by type t.
237
257
// It panics if t's Kind is not Complex64 or Complex128.
238
258
OverflowComplex (x complex128 ) bool
@@ -934,6 +954,46 @@ func canRangeFunc2(t *abi.Type) bool {
934
954
return yield .InCount == 2 && yield .OutCount == 1 && yield .Out (0 ).Kind () == abi .Bool
935
955
}
936
956
957
+ func (t * rtype ) Fields () iter.Seq [StructField ] {
958
+ return func (yield func (StructField ) bool ) {
959
+ for i := range t .NumField () {
960
+ if ! yield (t .Field (i )) {
961
+ return
962
+ }
963
+ }
964
+ }
965
+ }
966
+
967
+ func (t * rtype ) Methods () iter.Seq [Method ] {
968
+ return func (yield func (Method ) bool ) {
969
+ for i := range t .NumMethod () {
970
+ if ! yield (t .Method (i )) {
971
+ return
972
+ }
973
+ }
974
+ }
975
+ }
976
+
977
+ func (t * rtype ) Ins () iter.Seq [Type ] {
978
+ return func (yield func (Type ) bool ) {
979
+ for i := range t .NumIn () {
980
+ if ! yield (t .In (i )) {
981
+ return
982
+ }
983
+ }
984
+ }
985
+ }
986
+
987
+ func (t * rtype ) Outs () iter.Seq [Type ] {
988
+ return func (yield func (Type ) bool ) {
989
+ for i := range t .NumOut () {
990
+ if ! yield (t .Out (i )) {
991
+ return
992
+ }
993
+ }
994
+ }
995
+ }
996
+
937
997
// add returns p+x.
938
998
//
939
999
// The whySafe string is ignored, so that the function still inlines
0 commit comments