Skip to content

proposal: go/ast: add FieldList.Variables() iter.Seq2[*Ident, *Field] #73395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adonovan opened this issue Apr 16, 2025 · 0 comments
Open

proposal: go/ast: add FieldList.Variables() iter.Seq2[*Ident, *Field] #73395

adonovan opened this issue Apr 16, 2025 · 0 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Apr 16, 2025

Background: it is common when working with the go/ast package to need to enumerate the list of parameter or result variables declared by a function.
Proposal: We propose to add a Variables method to ast.FieldList that returns an iterator over the sequence of variables, as defined below.

package ast // go/ast

// Variables returns an iterator over each variable declared by a FieldList.
// Each variable is represented by a (name, field) pair, where name provides
// the name (if any), and the field provides the type and position.
func (list *FieldList) Variables() iter.Seq2[*Ident, *Field]

For implementation, see astutil.FlatFields in x/tools.

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Apr 16, 2025
@adonovan adonovan moved this to Incoming in Proposals Apr 18, 2025
@prattmic prattmic changed the title go/ast: add FieldList.Variables() iter.Seq2[*Ident, *Field] proposal: go/ast: add FieldList.Variables() iter.Seq2[*Ident, *Field] Apr 18, 2025
@gopherbot gopherbot added this to the Proposal milestone Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
Status: Incoming
Development

No branches or pull requests

3 participants