fold<X extends Object?> method

  1. @optionalTypeArgs
X fold<X extends Object?>(
  1. X success(
    1. V value
    ),
  2. X failure(
    1. dynamic error
    )
)

Applies success if this is a isValue or error if this is a isError.

Example:

final result: Result<Value> = possiblyFailingOperation()
result.fold(
     { (v) => log("operation failed with $v") },
     { (e) => log("operation succeeded with $e") }
)

success the function to apply if this is a isValue failure the function to apply if this is a isError returns the results of applying the function

Implementation

@optionalTypeArgs
X fold<X extends Object?>(
    X Function(V value) success, X Function(dynamic error) failure) {
  if (isValue) {
    return success(asValue!.value);
  } else {
    return failure(asError!.error);
  }
}