when<TResult extends Object?> method
- @optionalTypeArgs
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?>({
required TResult Function(String field0) str,
required TResult Function(PlatformInt64 field0) int,
required TResult Function(double field0) float,
required TResult Function(bool field0) bool,
required TResult Function(List<String> field0) listStr,
required TResult Function(Int64List field0) listInt,
}) {
final _that = this;
switch (_that) {
case PyArgument_Str():
return str(_that.field0);
case PyArgument_Int():
return int(_that.field0);
case PyArgument_Float():
return float(_that.field0);
case PyArgument_Bool():
return bool(_that.field0);
case PyArgument_ListStr():
return listStr(_that.field0);
case PyArgument_ListInt():
return listInt(_that.field0);
}
}