match<T> method

T match<T>({
  1. required T streetAddress(
    1. AddressStreet value
    ),
  2. required T number(
    1. AddressNumber value
    ),
  3. required T location(
    1. AddressLocation value
    ),
})

Implementation

T match<T>({
  required T Function(AddressStreet value) streetAddress,
  required T Function(AddressNumber value) number,
  required T Function(AddressLocation value) location,
}) {
  return switch (this._index) {
    0 => streetAddress(this._value as AddressStreet),
    1 => number(this._value as AddressNumber),
    2 => location(this._value as AddressLocation),
    _ => throw NativeException("Unrecognized case index ${this._index}")
  };
}