Skip to content

proposal: src/iter: iter.Seq2.Keys() and iter.Seq2.Values() #71658

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

Closed
petern48 opened this issue Feb 11, 2025 · 2 comments
Closed

proposal: src/iter: iter.Seq2.Keys() and iter.Seq2.Values() #71658

petern48 opened this issue Feb 11, 2025 · 2 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@petern48
Copy link

Proposal Details

Basically the same as the maps.Keys() and maps.Values() functions, written here except for iter.Seq2 datatype. I found that the existing implementations for maps.Keys() worked exactly for what I needed. The function doesn't work for the iter.Seq2 type, so I ended up writing the below function myself, simply replacing the datatypes. Seems like a useful addition to the standard library. Happy to submit a PR myself if this is approved.

func Keys[K, V any](seq iter.Seq2[K, V]) iter.Seq[K] {
 	return func(yield func(K) bool) {
 		for k, _ := range seq {
 			if !yield(k) {
 				return
 			}
 		}
 	}
 }

// Same with func Values() ...
@gopherbot gopherbot added this to the Proposal milestone Feb 11, 2025
@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Feb 11, 2025
@seankhliao
Copy link
Member

see #61898 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
None yet
Development

No branches or pull requests

4 participants