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

Add implementation of MultiUnzip to Option #980

Open
zekefast opened this issue Aug 6, 2024 · 3 comments
Open

Add implementation of MultiUnzip to Option #980

zekefast opened this issue Aug 6, 2024 · 3 comments

Comments

@zekefast
Copy link

zekefast commented Aug 6, 2024

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
@jswrenn
Copy link
Member

jswrenn commented Aug 6, 2024

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.

@zekefast
Copy link
Author

zekefast commented Aug 6, 2024

@jswrenn That would be great! I think there could be issues with Extend as well as it is not implemented for Option if remember it right.

@jswrenn
Copy link
Member

jswrenn commented Aug 6, 2024

Ah, oof that will be an issue, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants