-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problemsnull-aware-expressionsIssues proposing new expressions to manage nullIssues proposing new expressions to manage null
Description
Proposed solution to #360.
Where a ?? b
is sugar for a != null ? a : b
, there may be value in adding !!
defined as a == null ? null : b
.
Example: calling a function when the parameter is not null.
String? toPrint;
toPrint !! print(toPrint);
Example: awaiting a future when its not null
Future? fut;
fut !! await fut;
Example: asserting an object is fully initialized
assert(name !! age !! email !! password != null)
Similar to #219 except I think it has a few different advantages:
- extremely simple and consistent with an existing well-used and understood dart concept
- binary operator so left-to-right flow is easier to follow
- wouldn't interact with any other syntax (prefix ? is was proposed to interact with maps, lists, optional parameters, etc.)
Disadvantages:
- using
!
and not throwing an exception on null is confusing. Maybe?!
or!?
? - Limited usefulness
- repeat lhs required to take advantage of promotion
mdebbar, a14n, l7ssha, segfaultmedaddy, trietbui85 and 35 moresullenel, FMorschel, eddcorts, florian-obernberger, gruvw and 1 more
Metadata
Metadata
Assignees
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problemsnull-aware-expressionsIssues proposing new expressions to manage nullIssues proposing new expressions to manage null