lastWhereOptional method

Optional<T> lastWhereOptional(
  1. bool test(
    1. T element
    )
)

The last element satisfying test, or Optional.empty() if there are none.

Implementation

Optional<T> lastWhereOptional(bool Function(T element) test) {
  T? result;
  for (var element in this) {
    if (test(element)) result = element;
  }
  return Optional.ofNullable(result);
}