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

Add if not null operator: !? #706

Closed
mathieudevos opened this issue Nov 25, 2019 · 2 comments
Closed

Add if not null operator: !? #706

mathieudevos opened this issue Nov 25, 2019 · 2 comments
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@mathieudevos
Copy link

Simple suggestion, allow the negation of the if null operator: ?? with the following: !?.

This prevents you from running functions that cannot handle null input.

Example:

double foobar(double input) {
  return input / 2;
}

void printIt(dynamic input) {
  print(input.toString());
}

void main() {
  final foo = null;

  // Suggested method
  printIt(foo !? foobar(foo));

  // Current method
  printIt((foo == null) ? null : foobar(foo));
}

The current style just has a weird way of writing with the null repetition.
Alternatively we could allow the unary prefix to apply: !foo ?? foobar(foo) would also be acceptable.

@mathieudevos mathieudevos added the feature Proposed language feature that solves one or more problems label Nov 25, 2019
@natebosch
Copy link
Member

You might want to add a comment on #361 which proposes something similar but uses !! instead of !?

@lrhn
Copy link
Member

lrhn commented Nov 26, 2019

Agree, this is a duplicate of #361.

@lrhn lrhn closed this as completed Nov 26, 2019
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants