filter method
Returns None
if the option is None
, otherwise calls predicate
with
the wrapped value and returns:
Some(t)
if predicate returnstrue
(wheret
is the wrapped value)None
if predicate returnsfalse
.
Implementation
Option<T> filter(bool Function(T) predicate) {
final val = toNullable();
if (val != null && predicate(val)) {
return Some(val);
} else {
return None<T>();
}
}