isOkAnd method

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

Whether the result succeeded and its value satisfies predicate.

predicate is not called for an Err.

final passed = const Ok<int, String>(90).isOkAnd((score) => score >= 50);

Implementation

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