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

Support while let #22

Open
omjadas opened this issue Nov 20, 2021 · 0 comments
Open

Support while let #22

omjadas opened this issue Nov 20, 2021 · 0 comments

Comments

@omjadas
Copy link

omjadas commented Nov 20, 2021

I would find it useful for if_chain to also support while let.

if_chain! {
    if let Some(b) = a;
    while let Ok(c) = b;
    if let Some(d) = c;
    then {
        do_something_with_d(d);
    }
}

becomes:

if let Some(b) = a {
    while let Ok(c) = b {
        if let Some(d) = c {
            do_something_with_d(d);
        }
    }
}

I'm not sure how/if this should work with the else block. Perhaps something like the following could be done.

if_chain! {
    if let Some(b) = a;
    while let Ok(c) = b;
    if let Some(d) = c;
    then {
        do_something_with_d(d);
    } else {
        do_something_else();
    }
}

becomes:

if let Some(b) = a {
    let mut __executed = false;
    while let Ok(c) = b {
        __executed = true;
        if let Some(d) = c {
            do_something_with_d(d);
        } else {
            do_something_else();
        }
    }
    if !__executed {
        do_something_else();
    }
} else {
    do_something_else();
}
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

1 participant