Skip to content

iter: add more examples #73292

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
samsonkolge opened this issue Apr 9, 2025 · 2 comments
Open

iter: add more examples #73292

samsonkolge opened this issue Apr 9, 2025 · 2 comments
Labels
Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.

Comments

@samsonkolge
Copy link

Proposal Details

Background

The iter package was introduced in Go 1.22 as a new standard library package
for working with iterators. It provides important abstractions like Seq and
Seq2 types, along with the Pull and Pull2 functions.

Currently, the package has comprehensive documentation in the comment blocks,
but lacks an example_test.go file with concrete, runnable examples. This
makes it harder for users to understand the idiomatic usage patterns for
iterators, especially for the Pull functions.

Proposal

Add an example_test.go file to the iter package that demonstrates:

  1. Basic usage of Seq and Seq2 iterators
  2. How to properly create and consume iterators with range loops
  3. How to use Pull and Pull2 functions, including proper resource cleanup
  4. Common patterns for chaining and transforming iterators
  5. Examples of creating custom iterators

Expected Benefits

Having clear, runnable examples will:

  • Help users understand the iterator patterns more concretely
  • Demonstrate best practices for iterator usage (such as proper cleanup)
  • Provide copy-pastable code examples for common use cases
  • Complement the existing documentation with practical implementations

These examples would be especially helpful for this new package as developers
are still learning the idiomatic ways to use iterators in Go.

Implementation Plan

I'm willing to implement this improvement by creating a new example_test.go
file with comprehensive examples if the proposal is accepted.

/cc @golang/docs

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/664137 mentions this issue: docs: add examples for iter package

@gabyhelp
Copy link

gabyhelp commented Apr 9, 2025

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the Documentation Issues describing a change to documentation. label Apr 9, 2025
@seankhliao seankhliao changed the title title: docs: add examples for the iter package iter: add more examples Apr 9, 2025
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants