when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult internal(
    1. GlobalOptions globalOptions,
    2. String cacheDir,
    3. String patchDir
    ),
})

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( GlobalOptions globalOptions,  String cacheDir,  String patchDir)  internal,}) {final _that = this;
switch (_that) {
case _GlobalPatchOptions():
return internal(_that.globalOptions,_that.cacheDir,_that.patchDir);case _:
  throw StateError('Unexpected subclass');

}
}