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
T elementAtOrElse(int index, T Function(int) defaultValue) {
if (index < 0) {
return defaultValue(index);
}
final i = iterator();
int count = 0;
while (i.hasNext()) {
final element = i.next();
if (index == count++) {
return element;
}
}
return defaultValue(index);
}