elementAtOrElse method
Returns an element at the given index
or the result of calling the
defaultValue
function if the index
is out of bounds of this
collection.
Implementation
E elementAtOrElse(int index, E Function(int index) defaultValue) {
final iterator = this.iterator;
var elementIndex = 0;
while (iterator.moveNext()) {
if (index == elementIndex) return iterator.current;
elementIndex++;
}
return defaultValue(index);
}