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

[Error] return a ? Error() : b should work #7

Open
arian opened this issue Nov 19, 2015 · 0 comments
Open

[Error] return a ? Error() : b should work #7

arian opened this issue Nov 19, 2015 · 0 comments
Labels

Comments

@arian
Copy link
Owner

arian commented Nov 19, 2015

Instead of writing

MaybeError<int32> safe_divide(int32 a, int32 b) {
  if (b == 0) return Error(); 
  else return (a / b);
}

You should be able to write

MaybeError<int32> safe_divide(int32 a, int32 b) {
  return (b == 0) ? Error() : (a / b);
}
@arian arian added the error label Nov 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant