where method

Option<T> where(
  1. bool predicate(
    1. T
    )
)

Filters this Option based on the given predicate function.

Returns None if this Option is None, otherwise calls predicate with the held value, returning:

  • Some<T> if predicate returns true.
  • None<T> if predicate returns false.

See also: Rust: Option::filter()

Implementation

Option<T> where(bool Function(T) predicate) => switch (this) {
	Some(:T v) => predicate(v) ? this : None(),
	None() => this
};