firstWhereIndexedOptional method

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

The first element whose value and index satisfies test.

Returns Optional.empty() if there are no element and index satisfying test.

Implementation

Optional<T> firstWhereIndexedOptional(
    bool Function(int index, T element) test) {
  var index = 0;
  for (var element in this) {
    if (test(index++, element)) return Optional.of(element);
  }
  return Optional.empty();
}