-
Notifications
You must be signed in to change notification settings - Fork 18k
iter: documentation improvements #70986
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
Comments
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
here is an example from func Keys[Map ~map[K]V, K comparable, V any](m Map) iter.Seq[K] {
return func(yield func(K) bool) {
for k := range m {
if !yield(k) {
return
}
}
}
} |
Reading the links you sent the example you show is meant to demonstrate |
The referenced docs have this paragraph
Admittedly upon encountering this for the first time I thought "but how do I write one, so I can use it?" Would it be fine to do a PR that inserts a new paragraph and a short code before the above paragraph? Like a simple iterator over a slice just for simple illustration? |
Feel free to send a CL to improve the documentation, and/or add examples. Thanks! Also, it probably makes sense to have a link to the language spec's range over function part. |
The blog post https://go.dev/blog/range-functions also gives some examples of writing iterators. I'm not sure how much should be added to the package documentation. It's hard to know when to stop. The right approach might be to add a few Example functions. |
My current change is to have the maps.Keys iterator example as this is small enough, yet up to the point. The link to the for loop language spec also snugly fits in with the existing paragraph about "...often called by a range loop, as in...". Linking to more examples in the blog will IMHO also neatly fit in without overcrowding. |
Change https://go.dev/cl/638895 mentions this issue: |
Note that the self reference actually points to the package documentation that the CL improves. Feel free to submit your CL. |
When I click on the link, it brings me to the top of the page. This doesn't seem unreasonable. |
@3052 Understood, but it still seems OK to me as it currently is. |
Proposal Details
these
https://go.dev/pkg/iter/?m=old#Seq
https://go.dev/pkg/iter/?m=old#Seq2
both say this
"See the iter package documentation for more details" and link back to the same page:
https://go.dev/pkg/iter
also, the entire page does not give an example of implementing either type. technically yes, it does have the below example, but not an example of creating iter.Seq, and even the given example has a iter.Seq as input, so it would assume that you have already implemented iter.Seq without giving an example on how to do so
The text was updated successfully, but these errors were encountered: