Implement something like "coalesce" (javascripts || or phps ?:) #6582
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
This issue was originally filed by emiliopl...@gmail.com
What steps will reproduce the problem?
I need to get the first not null argument in:
var shortName = coalesce(person.alias, person.name, person.completeName); // like PL
but I can't write it because there are not functions with infinite arguments.
or may be
var shortName = person.alias ?: person.name ?: person.completeName; // like php
But you must implement the operator ?: (or other with the same meaning)
or may be
var shortName = person.alias || person.name || person.completeName; // like JavaScript
But || it's only for booleans.
or may be
var shortName = [person.alias, person.name, person.completeName].firstNotNull();
But we can't extend List.
or may be
var shortName = coalesce([person.alias, person.name, person.completeName]);
but I don't like it. It's the only solution?
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
The text was updated successfully, but these errors were encountered: