when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String roleProfileId,
    2. String skillId,
    3. String? skillName,
    4. int expectedMastery,
    )
)

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( String roleProfileId,  String skillId,  String? skillName,  int expectedMastery)  $default,) {final _that = this;
switch (_that) {
case _RoleSkillExpectationModel():
return $default(_that.roleProfileId,_that.skillId,_that.skillName,_that.expectedMastery);case _:
  throw StateError('Unexpected subclass');

}
}