firstNonNull function
- @Deprecated('Use ?? and ArgumentError.checkNotNull. Will be removed in 4.0.0')
- dynamic o1,
- dynamic o2, [
- dynamic o3,
- dynamic o4,
Returns the first non-null argument.
If all arguments are null, throws an ArgumentError.
Users of Dart SDK 2.1 or later should prefer:
var value = o1 ?? o2 ?? o3 ?? o4;
ArgumentError.checkNotNull(value);
If o1
is an Optional, this can be accomplished with o1.or(o2)
.
Implementation
@Deprecated('Use ?? and ArgumentError.checkNotNull. Will be removed in 4.0.0')
dynamic firstNonNull(o1, o2, [o3, o4]) {
// TODO(cbracken): make this generic.
if (o1 != null) return o1;
if (o2 != null) return o2;
if (o3 != null) return o3;
if (o4 != null) return o4;
throw ArgumentError('All arguments were null');
}