Closed
Description
openedon Apr 20, 2018
First, there are currently 474 issues|PRs here that contain "if let", so I hope I'm not duplicating something already discussed.
This idea is quite close to #929, but instead of allowing to &&
let
s, it'd allow to &&
with a bool
.
Basically, the idea looks like this:
if let Some(x) = y && x > 42 {
println!("foo");
} else {
println!("bar");
}
// Would be equivalent to:
if let Some(x) = y {
if x > 42 {
println!("foo");
} else {
println!("bar");
}
} else {
println!("bar");
}
This pattern is something that frequently occurred to me, and I'm finding it painful to always look for workarounds.
The constraints to this pattern would be:
- Only && could be used after a let, especially if a || is wanted it must be as a child node of the && (required so that the RHS could be evaluated with the let binding in scope)
- For the time being, it is restricted to one let and one or more && with bools, leaving ideas like
if let Some((a, b)) = x && a > 42 && let Some(c) = b.unwrap()
for later (modulo Support && in if let expressions #929)
What do you think about this idea?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment