when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int? plusOne,
    2. int? minusOne,
    3. int? confused,
    4. int? eyes,
    5. int? heart,
    6. int? hooray,
    7. int? laugh,
    8. int? rocket,
    9. int totalCount,
    10. ModelUri? url,
    )
)

A switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

@optionalTypeArgs
TResult when<TResult extends Object?>(
  TResult Function(
          int? plusOne,
          int? minusOne,
          int? confused,
          int? eyes,
          int? heart,
          int? hooray,
          int? laugh,
          int? rocket,
          int totalCount,
          ModelUri? url)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubReactionValue():
      return $default(
          _that.plusOne,
          _that.minusOne,
          _that.confused,
          _that.eyes,
          _that.heart,
          _that.hooray,
          _that.laugh,
          _that.rocket,
          _that.totalCount,
          _that.url);
    case _:
      throw StateError('Unexpected subclass');
  }
}