filter method

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

Applies the function only if the Option is Some, otherwise returns None.

Implementation

Option<T> filter(bool Function(T value) predicate) {
  if (this is Some<T>) {
    final value = (this as Some<T>).value;
    if (predicate(value)) {
      return this;
    }
  }
  return None<T>();
}