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

Syntax proposal guard let #1302

Closed
jaredly opened this issue Jun 14, 2017 · 1 comment
Closed

Syntax proposal guard let #1302

jaredly opened this issue Jun 14, 2017 · 1 comment
Labels
Parser parsing reason code into an AST RFC For larger proposals/ideas that will need discussion

Comments

@jaredly
Copy link
Contributor

jaredly commented Jun 14, 2017

A follow-up to #1301, swift has this other nice piece of sugar, guard let.
Here's what it might look like in reason

guard let Some(val) = something else { None };
// ...rest of the code

which translates to

switch something {
| Some(val) => {
  // ...rest of the code
}
| _ => None
}

More generally

guard let %pattern = %value else { %if_not_matched_expression };
%if_matched_expression

becomes

switch %value {
| %pattern => %if_matched_expression
| _ => %if_not_matched_expression
}

early returns can be super helpful for readability imo.

ppx_let does a similar kind of thing, albeit with somewhat more magic https://github.com/janestreet/ppx_let

@jaredly jaredly added RFC For larger proposals/ideas that will need discussion Parser parsing reason code into an AST KIND: FEATURE REQUEST and removed KIND: FEATURE REQUEST labels Jun 14, 2018
@anmonteiro
Copy link
Member

unlikely we'll do this

@anmonteiro anmonteiro closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Parser parsing reason code into an AST RFC For larger proposals/ideas that will need discussion
Projects
None yet
Development

No branches or pull requests

2 participants