isOkAnd method

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

Checks if this is a success and the value matches the predicate.

Returns true only if this is Ok and predicate returns true for the value. Use this for conditional logic without extracting the value, maintaining type safety. For other checks, use pattern matching or isOk.

Example:

if (result.isOkAnd((value) => value > 0)) {
  print('Positive value');
}

Implementation

bool isOkAnd(bool Function(T value) predicate) => switch (this) {
  Ok(:final value) => predicate(value),
  Err() => false,
};