-
Notifications
You must be signed in to change notification settings - Fork 430
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
Syntax proposal if let
#1301
Comments
Yes its occasionally nice being able to do (a bit redundant here but this is the specific use case I had been thinking about):
|
Other discussion from the ocaml folks I'm not very moved by their counterarguments. I think |
Another thing that swift's
is much nicer imo than
(especially if |
I think using e.g. if let Some(x) = optx
and Some(y) = opty
and Some(z) = optz
{
// all your things are here
} |
It's a cool idea! One thing that might be confusing is that I want successive cases to be able to use values from previous cases.
is invalid. |
Fair, this pattern seems like a pretty great way to guard: if let Some(x) = getValue(),
let Some(y) = doSomething(x),
let Some(z) = doSomethingElse(z) {
doSomethingCool(z);
} else {
failwith("Couldn't do the thing!");
} The ability to use the inner values makes it superior to
It'd have to be expressed as a series of nested |
For reference, this is similar to Elixir's opts = %{width: 10, height: 15}
with {:ok, width} <- Map.fetch(opts, :width),
{:ok, height} <- Map.fetch(opts, :height),
do: {:ok, width * height}
#=> {:ok, 150} |
In swift, there's this nice construct for simple destructuring
It's basically a one-armed match.
It would be super handy to have that for reason, and I imagine it would look like
which we'd translate to
The text was updated successfully, but these errors were encountered: