whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String? congestion,
    2. bool? debug,
    3. String? bbrProfile,
    4. Bandwidth? brutalUp,
    5. Bandwidth? brutalDown,
    6. UdpHop? udpHop,
    7. int? initStreamReceiveWindow,
    8. int? maxStreamReceiveWindow,
    9. int? initConnectionReceiveWindow,
    10. int? maxConnectionReceiveWindow,
    11. int? maxIdleTimeout,
    12. int? keepAlivePeriod,
    13. bool? disablePathMTUDiscovery,
    14. int? maxIncomingStreams,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

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

Implementation

@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  TResult? Function(
          String? congestion,
          bool? debug,
          String? bbrProfile,
          Bandwidth? brutalUp,
          Bandwidth? brutalDown,
          UdpHop? udpHop,
          int? initStreamReceiveWindow,
          int? maxStreamReceiveWindow,
          int? initConnectionReceiveWindow,
          int? maxConnectionReceiveWindow,
          int? maxIdleTimeout,
          int? keepAlivePeriod,
          bool? disablePathMTUDiscovery,
          int? maxIncomingStreams)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _QuicParamsConfig() when $default != null:
      return $default(
          _that.congestion,
          _that.debug,
          _that.bbrProfile,
          _that.brutalUp,
          _that.brutalDown,
          _that.udpHop,
          _that.initStreamReceiveWindow,
          _that.maxStreamReceiveWindow,
          _that.initConnectionReceiveWindow,
          _that.maxConnectionReceiveWindow,
          _that.maxIdleTimeout,
          _that.keepAlivePeriod,
          _that.disablePathMTUDiscovery,
          _that.maxIncomingStreams);
    case _:
      return null;
  }
}