maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
  1. TResult $default(
    1. String? sha,
    2. String? message,
    3. int commentCount,
    4. int additionsCount,
    5. int deletionsCount,
    6. int totalCount,
    7. ModelUri? url,
    8. ModelUri? htmlUrl,
    9. ModelUri? commentsUrl,
    10. GithubUserModelRef? author,
    11. GithubUserModelRef? committer,
    12. ModelTimestamp? authorDate,
    13. ModelTimestamp? committerDate,
    14. List<GithubCommitModel> parents,
    15. List<GithubContentModel> contents,
    16. 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? sha,
          String? message,
          int commentCount,
          int additionsCount,
          int deletionsCount,
          int totalCount,
          ModelUri? url,
          ModelUri? htmlUrl,
          ModelUri? commentsUrl,
          @refParam GithubUserModelRef? author,
          @refParam GithubUserModelRef? committer,
          ModelTimestamp? authorDate,
          ModelTimestamp? committerDate,
          @jsonParam List<GithubCommitModel> parents,
          @jsonParam List<GithubContentModel> contents,
          bool fromServer)?
      $default, {
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case _GithubCommitModel() when $default != null:
      return $default(
          _that.sha,
          _that.message,
          _that.commentCount,
          _that.additionsCount,
          _that.deletionsCount,
          _that.totalCount,
          _that.url,
          _that.htmlUrl,
          _that.commentsUrl,
          _that.author,
          _that.committer,
          _that.authorDate,
          _that.committerDate,
          _that.parents,
          _that.contents,
          _that.fromServer);
    case _:
      return orElse();
  }
}