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

Feature request: try_unzip #402

Open
jplatte opened this issue Feb 6, 2020 · 8 comments
Open

Feature request: try_unzip #402

jplatte opened this issue Feb 6, 2020 · 8 comments
Labels
fallible-iterator Iterator of results/options

Comments

@jplatte
Copy link
Contributor

jplatte commented Feb 6, 2020

fn try_unzip<A, B, E, FromA, FromB>(self) -> Result<(FromA, FromB), E>
where
    FromA: Default + Extend<A>,
    FromB: Default + Extend<B>,
    Self: Iterator<Item = Result<(A, B), E>>,
{ ... }

As with my previous feature request, I'd be willing to implement this myself if it is considered useful enough for inclusion :)

@CGMossa
Copy link

CGMossa commented Mar 29, 2020

I've hit this same sort of issue a couple of this, and I believe there could be a really nice implementation of unzipping. I don't know about Result-type though. I am thinking something like:

let (vec_x,_vec_y, _) = vec![(122, 4214, "A", "1"), (200, 14, "B", "1")].iter().cloned().unzip();

Also something that utilizes .. in that sort of notation.

I'd be willing to help out, if this could be made more concrete?

@jplatte
Copy link
Contributor Author

jplatte commented Mar 29, 2020

@CGMossa An unzip that creates more than two collections is an entirely orthogonal feature to the fallible unzip that I've proposed here. It could be implemented as a macro iunzip!, parallel to izip!.

@CGMossa
Copy link

CGMossa commented Mar 29, 2020

Thanks. I'll make a new issue.

@Boscop
Copy link

Boscop commented Jul 5, 2020

@CGMossa Do you have a link to the issue? I'm also interested in a multi-unzip.

@CGMossa
Copy link

CGMossa commented Jul 6, 2020

@Boscop I don't think that I made an issue.

@jplatte
Copy link
Contributor Author

jplatte commented Jul 6, 2020

For future reference, there is an existing issue for that at #362.

@scottlamb
Copy link

I was looking for iter.try_unzip()? and eventually realized there's a slightly more awkward spelling that works fine: iter.process_results(|iter| iter.unzip())?.

@Philippe-Cholet
Copy link
Member

We have try_collect (in conflict with nightly) and some *_ok methods that we might expand a bit but process_results is quite useful for the general case.

@Philippe-Cholet Philippe-Cholet added the fallible-iterator Iterator of results/options label Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fallible-iterator Iterator of results/options
Projects
None yet
Development

No branches or pull requests

5 participants