maybeMap<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
  1. TResult requestCancelled(
    1. RequestCancelled value
    )?,
  2. TResult unauthorisedRequest(
    1. UnauthorisedRequest value
    )?,
  3. TResult unauthorisedRequestApple(
    1. UnauthorisedRequestApple value
    )?,
  4. TResult badRequest(
    1. BadRequest value
    )?,
  5. TResult notFound(
    1. NotFound value
    )?,
  6. TResult methodNotAllowed(
    1. MethodNotAllowed value
    )?,
  7. TResult notAcceptable(
    1. NotAcceptable value
    )?,
  8. TResult requestTimeout(
    1. RequestTimeout value
    )?,
  9. TResult sendTimeout(
    1. SendTimeout value
    )?,
  10. TResult conflict(
    1. Conflict value
    )?,
  11. TResult internalServerError(
    1. InternalServerError value
    )?,
  12. TResult notImplemented(
    1. NotImplemented value
    )?,
  13. TResult serviceUnavailable(
    1. ServiceUnavailable value
    )?,
  14. TResult noInternetConnection(
    1. NoInternetConnection value
    )?,
  15. TResult formatException(
    1. FormatException value
    )?,
  16. TResult unableToProcess(
    1. UnableToProcess value
    )?,
  17. TResult defaultError(
    1. DefaultError value
    )?,
  18. TResult unexpectedError(
    1. UnexpectedError value
    )?,
  19. TResult otpExpired(
    1. OtpExpired value
    )?,
  20. required TResult orElse(),
})

A variant of map that fallback to returning orElse.

It is equivalent to doing:

switch (sealedClass) {
  case final Subclass value:
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeMap<TResult extends Object?>({TResult Function( RequestCancelled value)?  requestCancelled,TResult Function( UnauthorisedRequest value)?  unauthorisedRequest,TResult Function( UnauthorisedRequestApple value)?  unauthorisedRequestApple,TResult Function( BadRequest value)?  badRequest,TResult Function( NotFound value)?  notFound,TResult Function( MethodNotAllowed value)?  methodNotAllowed,TResult Function( NotAcceptable value)?  notAcceptable,TResult Function( RequestTimeout value)?  requestTimeout,TResult Function( SendTimeout value)?  sendTimeout,TResult Function( Conflict value)?  conflict,TResult Function( InternalServerError value)?  internalServerError,TResult Function( NotImplemented value)?  notImplemented,TResult Function( ServiceUnavailable value)?  serviceUnavailable,TResult Function( NoInternetConnection value)?  noInternetConnection,TResult Function( FormatException value)?  formatException,TResult Function( UnableToProcess value)?  unableToProcess,TResult Function( DefaultError value)?  defaultError,TResult Function( UnexpectedError value)?  unexpectedError,TResult Function( OtpExpired value)?  otpExpired,required TResult orElse(),}){
final _that = this;
switch (_that) {
case RequestCancelled() when requestCancelled != null:
return requestCancelled(_that);case UnauthorisedRequest() when unauthorisedRequest != null:
return unauthorisedRequest(_that);case UnauthorisedRequestApple() when unauthorisedRequestApple != null:
return unauthorisedRequestApple(_that);case BadRequest() when badRequest != null:
return badRequest(_that);case NotFound() when notFound != null:
return notFound(_that);case MethodNotAllowed() when methodNotAllowed != null:
return methodNotAllowed(_that);case NotAcceptable() when notAcceptable != null:
return notAcceptable(_that);case RequestTimeout() when requestTimeout != null:
return requestTimeout(_that);case SendTimeout() when sendTimeout != null:
return sendTimeout(_that);case Conflict() when conflict != null:
return conflict(_that);case InternalServerError() when internalServerError != null:
return internalServerError(_that);case NotImplemented() when notImplemented != null:
return notImplemented(_that);case ServiceUnavailable() when serviceUnavailable != null:
return serviceUnavailable(_that);case NoInternetConnection() when noInternetConnection != null:
return noInternetConnection(_that);case FormatException() when formatException != null:
return formatException(_that);case UnableToProcess() when unableToProcess != null:
return unableToProcess(_that);case DefaultError() when defaultError != null:
return defaultError(_that);case UnexpectedError() when unexpectedError != null:
return unexpectedError(_that);case OtpExpired() when otpExpired != null:
return otpExpired(_that);case _:
  return orElse();

}
}