elementAtOrElse method
Returns the index
th element. If the index is out of bounds the orElse
supplier function is called to provide a value.
Example:
['a', 'b'].elementAtOrElse(2, () => ''); // ''
Implementation
T elementAtOrElse(int index, T Function() orElse) {
RangeError.checkNotNegative(index, 'index');
ArgumentError.checkNotNull(index);
ArgumentError.checkNotNull(orElse, 'orElse');
try {
return elementAt(index);
} catch (error) {
return orElse();
}
}