when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult account(
    1. SplTokenAccountDataInfo info,
    2. String type,
    3. String? accountType
    ),
  2. required TResult mint(
    1. MintAccountDataInfo info,
    2. String type,
    3. String? accountType
    ),
  3. required TResult unknown(
    1. String type
    ),
})

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( SplTokenAccountDataInfo info,  String type,  String? accountType)  account,required TResult Function( MintAccountDataInfo info,  String type,  String? accountType)  mint,required TResult Function( String type)  unknown,}) {final _that = this;
switch (_that) {
case TokenAccountData():
return account(_that.info,_that.type,_that.accountType);case MintAccountData():
return mint(_that.info,_that.type,_that.accountType);case UnknownAccountData():
return unknown(_that.type);}
}