maybeWhen<TResult extends Object?> method

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

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( SplTokenAccountDataInfo info,  String type,  String? accountType)?  account,TResult Function( MintAccountDataInfo info,  String type,  String? accountType)?  mint,TResult Function( String type)?  unknown,required TResult orElse(),}) {final _that = this;
switch (_that) {
case TokenAccountData() when account != null:
return account(_that.info,_that.type,_that.accountType);case MintAccountData() when mint != null:
return mint(_that.info,_that.type,_that.accountType);case UnknownAccountData() when unknown != null:
return unknown(_that.type);case _:
  return orElse();

}
}