when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int? id,
    2. String? body,
    3. String? previousBody,
    4. String? authorAssociation,
    5. String? commitId,
    6. String? sha,
    7. String? state,
    8. int? reviewId,
    9. GithubTimelineEvent event,
    10. GithubUserModel? user,
    11. GithubUserModel? from,
    12. GithubUserModel? to,
    13. GithubProjectModel? project,
    14. GithubMilestoneValue? milestone,
    15. GithubReactionValue? reaction,
    16. GithubIssueModel? issue,
    17. GithubPullRequestModel? pullRequest,
    18. GithubLabelValue? label,
    19. ModelUri? url,
    20. ModelUri? commitUrl,
    21. ModelUri? htmlUrl,
    22. ModelUri? issueUrl,
    23. ModelUri? links,
    24. ModelUri? pullRequestUrl,
    25. ModelTimestamp createdAt,
    26. ModelTimestamp updatedAt,
    27. bool fromServer,
    )
)

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? id,
          String? body,
          String? previousBody,
          String? authorAssociation,
          String? commitId,
          String? sha,
          String? state,
          int? reviewId,
          GithubTimelineEvent event,
          @jsonParam GithubUserModel? user,
          @jsonParam GithubUserModel? from,
          @jsonParam GithubUserModel? to,
          @jsonParam GithubProjectModel? project,
          @jsonParam GithubMilestoneValue? milestone,
          @jsonParam GithubReactionValue? reaction,
          @jsonParam GithubIssueModel? issue,
          @jsonParam GithubPullRequestModel? pullRequest,
          @jsonParam GithubLabelValue? label,
          ModelUri? url,
          ModelUri? commitUrl,
          ModelUri? htmlUrl,
          ModelUri? issueUrl,
          ModelUri? links,
          ModelUri? pullRequestUrl,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubIssueTimelineModel():
      return $default(
          _that.id,
          _that.body,
          _that.previousBody,
          _that.authorAssociation,
          _that.commitId,
          _that.sha,
          _that.state,
          _that.reviewId,
          _that.event,
          _that.user,
          _that.from,
          _that.to,
          _that.project,
          _that.milestone,
          _that.reaction,
          _that.issue,
          _that.pullRequest,
          _that.label,
          _that.url,
          _that.commitUrl,
          _that.htmlUrl,
          _that.issueUrl,
          _that.links,
          _that.pullRequestUrl,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      throw StateError('Unexpected subclass');
  }
}