firstWhereOptional method
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();
}