You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reflect.Type.Fields() iter.Seq[StructField] and reflect.Type.Methods() iter.Seq[Method] would be more convenient than having to call i := range myType.NumFields() and myType.Field(i) etc.
You could also add iterators to reflect.Value as well but those are less obviously useful. Probably worth doing just for completeness though.
The text was updated successfully, but these errors were encountered:
Alternatively, the method value could be the iterator as opposed to returning an iterator, like so:
package reflect
typeTypeinterface {
...// Fields is a go1.23 iterator over all the fields of a struct type (etc).//// Example: for ftype := range t.Fields { ... }Fields(yieldfunc(ftype*Func) bool)
}
func (t*rtype) Fields(yieldfunc(ftype*Func) bool) {
fori:=ranget.NumFields() {
if!yield(t.Field(i)) {
break
}
}
}
Proposal Details
reflect.Type.Fields() iter.Seq[StructField]
andreflect.Type.Methods() iter.Seq[Method]
would be more convenient than having to calli := range myType.NumFields()
andmyType.Field(i)
etc.You could also add iterators to
reflect.Value
as well but those are less obviously useful. Probably worth doing just for completeness though.The text was updated successfully, but these errors were encountered: