@@ -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,55 @@ 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
+ if t .Kind () != Struct {
959
+ panic ("reflect: Fields of non-struct type " + t .String ())
960
+ }
961
+ return func (yield func (StructField ) bool ) {
962
+ for i := range t .NumField () {
963
+ if ! yield (t .Field (i )) {
964
+ return
965
+ }
966
+ }
967
+ }
968
+ }
969
+
970
+ func (t * rtype ) Methods () iter.Seq [Method ] {
971
+ return func (yield func (Method ) bool ) {
972
+ for i := range t .NumMethod () {
973
+ if ! yield (t .Method (i )) {
974
+ return
975
+ }
976
+ }
977
+ }
978
+ }
979
+
980
+ func (t * rtype ) Ins () iter.Seq [Type ] {
981
+ if t .Kind () != Func {
982
+ panic ("reflect: Ins of non-func type " + t .String ())
983
+ }
984
+ return func (yield func (Type ) bool ) {
985
+ for i := range t .NumIn () {
986
+ if ! yield (t .In (i )) {
987
+ return
988
+ }
989
+ }
990
+ }
991
+ }
992
+
993
+ func (t * rtype ) Outs () iter.Seq [Type ] {
994
+ if t .Kind () != Func {
995
+ panic ("reflect: Outs of non-func type " + t .String ())
996
+ }
997
+ return func (yield func (Type ) bool ) {
998
+ for i := range t .NumOut () {
999
+ if ! yield (t .Out (i )) {
1000
+ return
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+
937
1006
// add returns p+x.
938
1007
//
939
1008
// The whySafe string is ignored, so that the function still inlines
0 commit comments