isSomeAnd method

bool isSomeAnd(
  1. bool predicate(
    1. T value
    )
)

Whether a value is present and satisfies predicate.

predicate is not called when the option is absent.

final isAdult = const Some<int>(21).isSomeAnd((age) => age >= 18); // true

Implementation

bool isSomeAnd(bool Function(T value) predicate) {
  return switch (this) {
    Some<T>(:final value) => predicate(value),
    None<T>() => false,
  };
}