filter method
Returns None if the option is None, otherwise calls predicate
with the wrapped value and returns:
Some(t)
ifpredicate
returnstrue
(wheret
is the wrapped value), andNone
ifpredicate
returnsfalse
.
This function works similar to Iterable.where. You can imagine
the Option<T>
being an iterator over one or zero elements. filter()
lets you decide which elements to keep.
Implementation
Option<T> filter(bool Function(T value) predicate) =>
isSome && predicate(_someValue) ? Some(_someValue) : None<T>();