when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- ChatCompletionListObject object,
- List<
CreateChatCompletionResponse> data, - String? firstId,
- String? lastId,
- bool hasMore,
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( ChatCompletionListObject object, List<CreateChatCompletionResponse> data, @JsonKey(name: 'first_id', includeIfNull: false) String? firstId, @JsonKey(name: 'last_id', includeIfNull: false) String? lastId, @JsonKey(name: 'has_more') bool hasMore) $default,) {final _that = this;
switch (_that) {
case _ChatCompletionList():
return $default(_that.object,_that.data,_that.firstId,_that.lastId,_that.hasMore);case _:
throw StateError('Unexpected subclass');
}
}