Skip to content
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

proposal: archive/tar: add iterator form of (&Reader).Next() #68062

Open
sivchari opened this issue Jun 19, 2024 · 2 comments
Open

proposal: archive/tar: add iterator form of (&Reader).Next() #68062

sivchari opened this issue Jun 19, 2024 · 2 comments
Labels
Milestone

Comments

@sivchari
Copy link
Contributor

sivchari commented Jun 19, 2024

Proposal Details

In Go 1.23, we can use range-over-func a.k.a iterator and developers propose to apply for the package into some packages.

For instance, the following issues are easy to know what kind of content are proposed.
#61897
#64341

This proposal is similar with above it.
I think it's good to apply for archive/tar, too.

func (tr *Reader) NextIter() iter.Seq2[*Header, error] {
	return func(yield func(*Header, error) bool) {
		hdr, err := tr.Next()
		if err == io.EOF {
			return
		}
		if !yield(hdr, err) {
			return
		}
	}
}

Thanks.

@gopherbot gopherbot added this to the Proposal milestone Jun 19, 2024
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Jun 19, 2024
@ianlancetaylor
Copy link
Member

Perhaps AllHeaders would be a better name.

Also I think error handling for this sort of iterator is currently an open issue. We may want to wait a bit to see if we come to a consensus on iterators where each value can fail.

@robpike
Copy link
Contributor

robpike commented Jun 19, 2024

I think that the question of adding iterators to existing packages is an example of what I was talking about in #67510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

4 participants