mapBoth<R> method

Deferred<R> mapBoth<R>({
  1. required R success(
    1. T result
    ),
  2. required Object error(
    1. Object error
    ),
})

Transforms both the contained success and error values based on the results of the callback functions success and error respectively.

Implementation

Deferred<R> mapBoth<R>({
  required R Function(T result) success,
  required Object Function(Object error) error,
}) {
  if (this is _InProgress) {
    return Deferred.inProgress();
  } else if (this is _Error) {
    final e = this as _Error;
    return Deferred.error(error(e.error), e.stackTrace);
  } else if (this is _Success) {
    final s = this as _Success<T>;
    return Deferred.success(success(s.results));
  } else {
    return Deferred.idle();
  }
}