when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int lamports,
    2. String owner,
    3. AccountData? data,
    4. bool executable,
    5. BigInt rentEpoch,
    )
)

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 lamports,  String owner,  AccountData? data,  bool executable, @JsonKey(fromJson: bigIntFromJson)  BigInt rentEpoch)  $default,) {final _that = this;
switch (_that) {
case _Account():
return $default(_that.lamports,_that.owner,_that.data,_that.executable,_that.rentEpoch);case _:
  throw StateError('Unexpected subclass');

}
}