withResultAsync method

FutureResult<T, dynamic> withResultAsync(
  1. Future<void> withFunction(
    1. T
    )
)

Executes the anonymous function passing the current success value to it to support operation chaining but as a pass-through process. The original result object is automatically passed on to the next chain unchanged nor is it possible to pass on a new result type like with the "andThen" methods.

Example:

return doSomething()
  .andThen((r1) => r1.doSomething1())
  .withResultAsync((r2) => print(r2))
  .andThen((r2) => r2.doSomething3())

Implementation

FutureResult<T, dynamic> withResultAsync(
    Future<void> Function(T) withFunction) async {
  if (isSuccess) {
    try {
      await withFunction(_value);
    } catch (e) {
      return Result.error(e);
    }
  }

  return this;
}