firstOrElse method

T firstOrElse(
  1. T orElse()
)

Returns the first element. If there is no first element the orElse supplier function is called to provide a value.

Example:

['a', 'b'].firstOrElse(() => ''); // 'a'
[].firstOrElse(() => '');         // ''

Implementation

T firstOrElse(T Function() orElse) {
  ArgumentError.checkNotNull(orElse, 'orElse');
  return firstWhere((_) => true, orElse: orElse);
}