@@ -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"
@@ -255,6 +256,22 @@ type Type interface {
255
256
// CanSeq2 reports whether a [Value] with this type can be iterated over using [Value.Seq2].
256
257
CanSeq2 () bool
257
258
259
+ // Fields yields each field of a struct type.
260
+ // It panics if the type's Kind is not Struct.
261
+ Fields () iter.Seq [StructField ]
262
+
263
+ // Methods yields each method in the type's method set.
264
+ // See [Type.Method] for information on the yielded methods.
265
+ Methods () iter.Seq [Method ]
266
+
267
+ // Ins yields each input parameter of a function type, in order.
268
+ // It panics if the type's Kind is not Func.
269
+ Ins () iter.Seq [Type ]
270
+
271
+ // Outs yields each output parameter of a function type, in order.
272
+ // It panics if the type's Kind is not Func.
273
+ Outs () iter.Seq [Type ]
274
+
258
275
common () * abi.Type
259
276
uncommon () * uncommonType
260
277
}
@@ -934,6 +951,46 @@ func canRangeFunc2(t *abi.Type) bool {
934
951
return yield .InCount == 2 && yield .OutCount == 1 && yield .Out (0 ).Kind () == abi .Bool
935
952
}
936
953
954
+ func (t * rtype ) Fields () iter.Seq [StructField ] {
955
+ return func (yield func (StructField ) bool ) {
956
+ for i := range t .NumField () {
957
+ if ! yield (t .Field (i )) {
958
+ return
959
+ }
960
+ }
961
+ }
962
+ }
963
+
964
+ func (t * rtype ) Methods () iter.Seq [Method ] {
965
+ return func (yield func (Method ) bool ) {
966
+ for i := range t .NumMethod () {
967
+ if ! yield (t .Method (i )) {
968
+ return
969
+ }
970
+ }
971
+ }
972
+ }
973
+
974
+ func (t * rtype ) Ins () iter.Seq [Type ] {
975
+ return func (yield func (Type ) bool ) {
976
+ for i := range t .NumIn () {
977
+ if ! yield (t .In (i )) {
978
+ return
979
+ }
980
+ }
981
+ }
982
+ }
983
+
984
+ func (t * rtype ) Outs () iter.Seq [Type ] {
985
+ return func (yield func (Type ) bool ) {
986
+ for i := range t .NumOut () {
987
+ if ! yield (t .Out (i )) {
988
+ return
989
+ }
990
+ }
991
+ }
992
+ }
993
+
937
994
// add returns p+x.
938
995
//
939
996
// The whySafe string is ignored, so that the function still inlines
0 commit comments