when<R> method
R
when<R>({
- required R loading(),
- required R data(
- T data
- required R failure(
- AppError error
Pattern matching
Implementation
R when<R>({
required R Function() loading,
required R Function(T data) data,
required R Function(AppError error) failure,
}) {
if (this is AppLoading<T>) return loading();
if (this is AppData<T>) return data((this as AppData<T>).data);
if (this is AppFailure<T>) return failure((this as AppFailure<T>).error);
throw Exception('Unhandled state');
}