@@ -18,6 +18,7 @@ package reflect
1818import (
1919 "internal/abi"
2020 "internal/goarch"
21+ "iter"
2122 "runtime"
2223 "strconv"
2324 "sync"
@@ -64,6 +65,10 @@ type Type interface {
6465 // This may make the executable binary larger but will not affect execution time.
6566 Method (int ) Method
6667
68+ // Methods returns an iterator that yields each method in the type's method set. The order is
69+ // equivalent to calling Method successively for each index i in the range [0, NumMethod()).
70+ Methods () iter.Seq [Method ]
71+
6772 // MethodByName returns the method with that name in the type's
6873 // method set and a boolean indicating if the method was found.
6974 //
@@ -172,6 +177,11 @@ type Type interface {
172177 // It panics if i is not in the range [0, NumField()).
173178 Field (i int ) StructField
174179
180+ // Fields returns an iterator that yields each struct field for struct type t. The order 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+
175185 // FieldByIndex returns the nested field corresponding
176186 // to the index sequence. It is equivalent to calling Field
177187 // successively for each index i.
@@ -208,6 +218,11 @@ type Type interface {
208218 // It panics if i is not in the range [0, NumIn()).
209219 In (i int ) Type
210220
221+ // Ins returns an iterator that yields each input parameter of function type t. The order
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+
211226 // Key returns a map type's key type.
212227 // It panics if the type's Kind is not Map.
213228 Key () Type
@@ -233,6 +248,11 @@ type Type interface {
233248 // It panics if i is not in the range [0, NumOut()).
234249 Out (i int ) Type
235250
251+ // Outs returns an iterator that yields each output parameter of function type t. The order
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+
236256 // OverflowComplex reports whether the complex128 x cannot be represented by type t.
237257 // It panics if t's Kind is not Complex64 or Complex128.
238258 OverflowComplex (x complex128 ) bool
@@ -934,6 +954,46 @@ func canRangeFunc2(t *abi.Type) bool {
934954 return yield .InCount == 2 && yield .OutCount == 1 && yield .Out (0 ).Kind () == abi .Bool
935955}
936956
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+
937997// add returns p+x.
938998//
939999// The whySafe string is ignored, so that the function still inlines
0 commit comments