maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String? name,
    3. String? resourceType,
    4. String? resourceId,
    5. String? userId,
    6. String? agentId,
    7. String? errorMessage,
    8. String? errorCode,
    9. int? pullRequestNumber,
    10. String? pullRequestUrl,
    11. String? pullRequestId,
    12. String? pullRequestBaseRef,
    13. GithubCopilotSessionStatus status,
    14. ModelTimestamp? completedAt,
    15. ModelTimestamp createdAt,
    16. ModelTimestamp updatedAt,
    17. bool fromServer,
    )?, {
  2. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

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

Implementation

@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  TResult Function(
          String id,
          String? name,
          String? resourceType,
          String? resourceId,
          String? userId,
          String? agentId,
          String? errorMessage,
          String? errorCode,
          int? pullRequestNumber,
          String? pullRequestUrl,
          String? pullRequestId,
          String? pullRequestBaseRef,
          GithubCopilotSessionStatus status,
          ModelTimestamp? completedAt,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)?
      $default, {
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case _GithubCopilotSessionModel() when $default != null:
      return $default(
          _that.id,
          _that.name,
          _that.resourceType,
          _that.resourceId,
          _that.userId,
          _that.agentId,
          _that.errorMessage,
          _that.errorCode,
          _that.pullRequestNumber,
          _that.pullRequestUrl,
          _that.pullRequestId,
          _that.pullRequestBaseRef,
          _that.status,
          _that.completedAt,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      return orElse();
  }
}