match<U> method

U match<U>({
  1. required U onSuccess(
    1. T
    ),
  2. required U onError(
    1. E
    ),
})

Achieves the same thing as a switch expression with pattern matching. You should consider using a switch expression, but sometimes the match function is simpler

Implementation

U match<U>({
  required U Function(T) onSuccess,
  required U Function(E) onError,
}) =>
    switch (this) {
      Success(:final value) => onSuccess(value),
      Error(error: final e) => onError(e),
    };