@@ -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.
6566Method (int ) Method
6667
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+
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()).
173178Field (i int ) StructField
174179
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+
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()).
209219In (i int ) Type
210220
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+
211226// Key returns a map type's key type.
212227// It panics if the type's Kind is not Map.
213228Key () Type
@@ -233,6 +248,11 @@ type Type interface {
233248// It panics if i is not in the range [0, NumOut()).
234249Out (i int ) Type
235250
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+
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.
238258OverflowComplex (x complex128 ) bool
@@ -934,6 +954,55 @@ func canRangeFunc2(t *abi.Type) bool {
934954return yield .InCount == 2 && yield .OutCount == 1 && yield .Out (0 ).Kind () == abi .Bool
935955}
936956
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+
9371006// add returns p+x.
9381007//
9391008// The whySafe string is ignored, so that the function still inlines
0 commit comments