itertools
itertools copied to clipboard
Add implementation of MultiUnzip to Option
Would it be possible to implement MultiUnzip on Option to make something like that possible to implement?
struct A {
a: u32,
b: u32,
c: u32,
}
let opt = Some(A { a: 1, b: 2, c: 3 });
let non: Option<A> = None;
let (a, b, c): (Option<_>, Option<_>, Option<_>) = opt
.map(|value| (value.a, value.b, value.c))
.multiunzip(); // a = Some(1); b = Some(2); c = Some(3)
let (a, b, c): (Option<_>, Option<_>, Option<_>) = non
.map(|value| (value.a, value.b, value.c))
.multiunzip(); // a = None; b = None; c = None
That's an elegant example! I'd have to think through this more (or just try it), but I think we could perhaps replace the IT: Iterator bound on the MultiZip impls with IT: IntoIterator.
@jswrenn That would be great! I think there could be issues with Extend as well as it is not implemented for Option if I remember it right.
Ah, oof that will be an issue, I think.
I asked question about idea to add implementation of Extend trait to Option type on iternals.rust-lang.org.
Let's see where the discussion leads us!