filter method

Option<T> filter(
  1. bool predicate(
    1. T value
    )
)

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:

  • Some(t) if predicate returns true (where t is the wrapped value), and
  • None if predicate returns false.

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>();