maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
  1. TResult transfer(
    1. SplTokenTransferInfo info,
    2. String type
    )?,
  2. TResult transferChecked(
    1. SplTokenTransferCheckedInfo info,
    2. String type
    )?,
  3. TResult generic(
    1. dynamic info,
    2. 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( SplTokenTransferInfo info,  String type)?  transfer,TResult Function( SplTokenTransferCheckedInfo info,  String type)?  transferChecked,TResult Function( dynamic info,  String type)?  generic,required TResult orElse(),}) {final _that = this;
switch (_that) {
case ParsedSplTokenTransferInstruction() when transfer != null:
return transfer(_that.info,_that.type);case ParsedSplTokenTransferCheckedInstruction() when transferChecked != null:
return transferChecked(_that.info,_that.type);case ParsedSplTokenGenericInstruction() when generic != null:
return generic(_that.info,_that.type);case _:
  return orElse();

}
}