-
Notifications
You must be signed in to change notification settings - Fork 18k
iter: Pull example in package doc loops forever #68073
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
Similar Issues (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
cc @ianlancetaylor for CL 593555 |
Thanks for catching that, added a fix to CL 593555. |
Change https://go.dev/cl/593555 mentions this issue: |
Possibly irrelevant: this seems close to runnable example code that demonstrates something about the nature of the for {
v1, ok1 := next()
v2, ok2 := next()
// short-circuit evaluation omits the yield of an (even-index, zero-value) pair, relative to !ok1 || !yield(v1, v2) || !ok2
if !ok1 || !ok2 || !yield(v1, v2) {
return
}
} |
Remove old return value. Use single variable range for iter.Seq[V]. Rewrite Pairs implementation to not loop forever. Fixes golang#68056 Fixes golang#68073 Change-Id: I7ede0fe8ed058bbd57869d87e17b7f2c3641f7dd Reviewed-on: https://go-review.googlesource.com/c/go/+/593555 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
The Pairs example (playground link) in the iter package doc seems incorrect, with it looping forever while emitting the same values.
Another minor issue is it has an extra bool in the returned func signature. (Probably an older signature).
If we correct the extra bool, we can see it timeout on the playground:
One possible correction might be this.
Unless someone beats me to it (which would be fine 😅), I will probably send a CL, but opening this issue in case any discussion is needed, including maybe I misunderstood the intent.
Finally, at first was unsure if it was meant to show overlapping vs. non-overlapping pairs. (I think the intent was probably non-overlapping pairs. I think
itertools.pairwise
in Python andstd::ranges::views::pairwise_transform
in C++ on the other hand both give overlapping pairs. That's probably fine, including this is just intended to be a simple example of usingiter.Pull
).The text was updated successfully, but these errors were encountered: