itertools
itertools copied to clipboard
Feature request: try_unzip
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 :)
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?
@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!.
Thanks. I'll make a new issue.
@CGMossa Do you have a link to the issue? I'm also interested in a multi-unzip.
@Boscop I don't think that I made an issue.
For future reference, there is an existing issue for that at #362.
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())?.
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.