-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/go/ast/inspector: add Inspector.PreorderSeq and top-level func All #67795
Comments
Change https://go.dev/cl/589955 mentions this issue: |
Filter makes a lot of sense. I'd prefer Each to One. |
I’ve seen the “go1.23 iterator” phrase a few times now. Do you we need to mention the “go1.23” in doc comments? I prefer to just say iterator. |
Initially I used that phrase because it wasn't obvious what the type of the function meant, especially when we spelled out the |
Based on Inspector already having a non-Seq form of the first method named Preorder, it seems like the Seq form should be PreorderSeq, so it is clear they are the same thing, with two different APIs. The top-level generic range seems like it could be called
That seems pretty nice. (It would still be documented as Preorder.) |
|
@jimmyfrasche As far as I can see the type argument to |
The example I provided is the only case currently: https://go.dev/play/p/BJqAA5eHLif More cases may present themselves in the future if inference expands. Here are some reasonable example of (hypothetical) type inference clashing with the name. for n := range F(inspector.All) {} // type inferred from F
for n = range inspector.All(p) {} // type inferred from n
return inspector.All // type inferred from enclosing function Presumably it would be still be easy to figure out |
|
FooOf for generics has been proposed many times and to date we have resisted each of them. I think we should continue to resist. That is, I don't think FooOf is an idiom we want to adopt in Go. The problem is that Of can be applied to many many functions that take arguments. Why not strings.ToLowerOf(s) and so on. We have not been entirely successful - reflect and go/types have some arguably spurious Of's - but let's not add more. |
I agree, 'Of' is just a redundant way of saying ( or [. |
My intent was only to signify that it's always conditional so that it stands out when that condition is not present. |
This proposal has been added to the active column of the proposals project |
Have all remaining concerns about this proposal been addressed? The proposal is to add:
|
Based on the discussion above, this proposal seems like a likely accept. The proposal is to add:
|
No change in consensus, so accepted. 🎉 The proposal is to add:
|
Change https://go.dev/cl/616218 mentions this issue: |
The golang.org/x/tools/go/ast/inspector package is all about iteration. We propose to add these two methods, which return go1.23 iterators. The first makes it easier to use break/return/continue within a
Preorder
-style iteration, and the second simplifies the most common case, of searching for nodes of a single type.Naming suggestions welcome.
The text was updated successfully, but these errors were encountered: