filter method

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

Keeps a present value only when it satisfies predicate.

final even = const Some<int>(3).filter((value) => value.isEven); // None()

Implementation

Option<T> filter(bool Function(T value) predicate) {
  return switch (this) {
    Some<T>(:final value) when predicate(value) => this,
    _ => None<T>(),
  };
}