when<R> method
R
when<R>({
- required R loading(),
- required R onData(
- T data
- required R onError(
- FKernalError error
- R initial()?,
Maps the state to a value using the provided functions.
Implementation
R when<R>({
required R Function() loading,
required R Function(T data) onData,
required R Function(FKernalError error) onError,
R Function()? initial,
}) {
return switch (this) {
ResourceInitial() => initial?.call() ?? loading(),
ResourceLoading() => loading(),
ResourceData(data: final d) => onData(d),
ResourceError(error: final e) => onError(e),
};
}