R
when<R>(- {required R success(
- Success<T>
),
- required R failure(
- Failure<T>
),
- required R loading(
- Loading<T>
)}
)
Implementation
R when<R>({
required R Function(Success<T>) success,
required R Function(Failure<T>) failure,
required R Function(Loading<T>) loading,
}) {
if (this is Success<T>) {
return success(this as Success<T>);
}
if (this is Failure<T>) {
return failure(this as Failure<T>);
}
if (this is Loading<T>) {
return loading(this as Loading<T>);
}
throw new Exception('Should never get here');
}