filter method

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

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)
  • None if predicate returns false.

Implementation

Option<T> filter(bool Function(T) predicate) {
  final val = toNullable();
  if (val != null && predicate(val)) {
    return Some(val);
  } else {
    return None<T>();
  }
}