when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String? sha,
- String? message,
- int commentCount,
- int additionsCount,
- int deletionsCount,
- int totalCount,
- ModelUri? url,
- ModelUri? htmlUrl,
- ModelUri? commentsUrl,
- GithubUserModelRef? author,
- GithubUserModelRef? committer,
- ModelTimestamp? authorDate,
- ModelTimestamp? committerDate,
- List<
GithubCommitModel> parents, - List<
GithubContentModel> contents, - 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(
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,
) {
final _that = this;
switch (_that) {
case _GithubCommitModel():
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 _:
throw StateError('Unexpected subclass');
}
}