mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? apiKey(
    1. SecuritySchemeApiKey value
    )?,
  2. TResult? http(
    1. SecuritySchemeHttp value
    )?,
  3. TResult? mutualTLS(
    1. SecuritySchemeMutualTLS value
    )?,
  4. TResult? oauth2(
    1. SecuritySchemeOauth2 value
    )?,
  5. TResult? openIdConnect(
    1. SecuritySchemeOpenIdConnect value
    )?,
})

A variant of map that fallback to returning null.

It is equivalent to doing:

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

Implementation

@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( SecuritySchemeApiKey value)?  apiKey,TResult? Function( SecuritySchemeHttp value)?  http,TResult? Function( SecuritySchemeMutualTLS value)?  mutualTLS,TResult? Function( SecuritySchemeOauth2 value)?  oauth2,TResult? Function( SecuritySchemeOpenIdConnect value)?  openIdConnect,}){
final _that = this;
switch (_that) {
case SecuritySchemeApiKey() when apiKey != null:
return apiKey(_that);case SecuritySchemeHttp() when http != null:
return http(_that);case SecuritySchemeMutualTLS() when mutualTLS != null:
return mutualTLS(_that);case SecuritySchemeOauth2() when oauth2 != null:
return oauth2(_that);case SecuritySchemeOpenIdConnect() when openIdConnect != null:
return openIdConnect(_that);case _:
  return null;

}
}