lastWhereIndexedOptional method

Optional<T> lastWhereIndexedOptional(
  1. bool test(
    1. int index,
    2. T element
    )
)

The last element whose index and value satisfies test.

Returns Optional.empty() if no element and index satisfies test.

Implementation

Optional<T> lastWhereIndexedOptional(bool Function(int index, T element) test) {
  T? result;
  var index = 0;
  for (var element in this) {
    if (test(index++, element)) result = element;
  }
  return Optional.ofNullable(result);
}