firstWhereOptional method

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

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

Implementation

Optional<T> firstWhereOptional(bool Function(T element) test) {
  for (var element in this) {
    if (test(element)) return Optional.of(element);
  }
  return Optional.empty();
}