mapDataAsync<S> method

FutureOr<NetworkResult<S>> mapDataAsync<S>({
  1. required Mapper<T, NetworkResult<S>> mapper,
})

Maps the success case to another type asynchronously, preserving the error case.

Implementation

FutureOr<NetworkResult<S>> mapDataAsync<S>({
  required Mapper<T, NetworkResult<S>> mapper,
}) async {
  return switch (this) {
    NetworkSuccess<T>() => await mapper((this as NetworkSuccess<T>).data),
    NetworkError<T>() => NetworkResult.error((this as NetworkError<T>).error),
  };
}