fromPredicate<R> static method

Result<R> fromPredicate<R>(
  1. bool predicate(),
  2. R onSuccess(),
  3. BaseError onError()
)

Constructs a Result by testing a condition. If the condition is true, the Result is a success with a certain value. If the condition is false, the Result is an error with a certain error.

Implementation

static Result<R> fromPredicate<R>(
  bool Function() predicate,
  R Function() onSuccess,
  BaseError Function() onError,
) {
  if (predicate()) {
    return successResult(onSuccess());
  } else {
    return errorResult(onError());
  }
}