Description
This issue was originally filed by waq...@gmail.com
In Javascript, one could provide defaults for objects that might be null in the following fashion:
foo = bar || default;
foo would be assigned bar, unless bar was falsy (e.g. null), in which case foo was assigned default instead.
In Dart, the operator || is only useful with booleans (as all other objects evaluate to false) and I could find no replacement for null-checks on objects.
I propose an operator like ?|| or a new keyword like orElse, which evaluates the expression to its left, returns it if it is not null, or otherwise returns the expression to its right. If the expression to the left is not null, the expression to the right should not be evaluated.
foo = null orElse 1; // foo = 1
foo = 2 orElse neverEvaluated; // foo = 2