lastWhere method

view source

E lastWhere (bool test(E element), {E orElse()}) inherited

Implementation

E lastWhere(bool test(E element), {E orElse()?}) {
  late E result;
  bool foundMatching = false;
  for (E element in this) {
    if (test(element)) {
      result = element;
      foundMatching = true;
    }
  }
  if (foundMatching) return result;
  if (orElse != null) return orElse();
  throw IterableElementError.noElement();
}