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. bool? brutalDisableLossCompensation,
    7. bool? disableChromeParrot,
    8. bool? disableGSO,
    9. bool? disableStatelessReset,
    10. int? initStreamReceiveWindow,
    11. int? maxStreamReceiveWindow,
    12. int? initConnectionReceiveWindow,
    13. int? maxConnectionReceiveWindow,
    14. int? maxIdleTimeout,
    15. int? keepAlivePeriod,
    16. bool? disablePathMTUDiscovery,
    17. 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,
    bool? brutalDisableLossCompensation,
    bool? disableChromeParrot,
    bool? disableGSO,
    bool? disableStatelessReset,
    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.brutalDisableLossCompensation,
        _that.disableChromeParrot,
        _that.disableGSO,
        _that.disableStatelessReset,
        _that.initStreamReceiveWindow,
        _that.maxStreamReceiveWindow,
        _that.initConnectionReceiveWindow,
        _that.maxConnectionReceiveWindow,
        _that.maxIdleTimeout,
        _that.keepAlivePeriod,
        _that.disablePathMTUDiscovery,
        _that.maxIncomingStreams,
      );
    case _:
      return null;
  }
}