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: iter: convert between Seq and Seq2 #67334

Open
leaxoy opened this issue May 13, 2024 · 4 comments
Open

proposal: iter: convert between Seq and Seq2 #67334

leaxoy opened this issue May 13, 2024 · 4 comments
Labels
Milestone

Comments

@leaxoy
Copy link

leaxoy commented May 13, 2024

Proposal Details

Recently we introduce iter package with two Seq types: Seq and Seq2.

Writing operations on both types are annoying and repetitive.

So I propose add function to convert Seq to Seq2 and Seq2 to Seq

Possible function signatures:

func Join[K, V, R any](s Seq2[K, V], f func(K, V) R) Seq[R] {
    return func(yield func(R) bool) {
        for k, v := range s {
            if !yield(f(k, V)) {
               break
            }
        }
    }
}

func Split[R, K, V any](s Seq[R], f func(R) (K, V)) Seq2[K, V] {
    return func(yield func(K, V) bool) {
        for x := range s {
            if !yield(f(x)) {
                break
            }
        }
    }
}
@gopherbot gopherbot added this to the Proposal milestone May 13, 2024
@jimmyfrasche
Copy link
Member

These are in the xiter thread as Map21 and Map12 #61898 (comment)

@leaxoy
Copy link
Author

leaxoy commented May 14, 2024

These are in the xiter thread as Map21 and Map12 #61898 (comment)

My personal thought is that this conversion is crucial for developers who write fundamental libraries, and placing it in xiter requires the basic library to introduce an additional package. In many cases, it is expected that only import the std.

@jbduncan
Copy link

Here's my two cents: Zip (Seq2 to Seq) and Unzip (Seq to Seq2). But Map21 and Map12 sound great to me too.

@jbduncan
Copy link

Oh, shoot, never mind, Zip is already taken by proposal #61898.

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