map<T> method

T map<T>({
  1. T onSuccess(
    1. Success success
    )?,
  2. T onError(
    1. ApiError error
    )?,
})

Implementation

T map<T>({
  T Function(Success success)? onSuccess,
  T Function(ApiError error)? onError,
}) {
  final ApiResult _this = this;

  if (_this is Success) {
    return onSuccess!(_this);
  } else if (_this is ApiError) {
    return onError!(_this);
  }
  throw Exception('ApiFailure $_this was not mapped');
}