when<R> method

R when<R>({
  1. required R loading(),
  2. required R data(
    1. T data
    ),
  3. required R error(
    1. BridgeError error
    ),
})

Folds the three states into a single value of type R. Every branch is required, mirroring the sealed family's exhaustiveness.

Implementation

R when<R>({
  required R Function() loading,
  required R Function(T data) data,
  required R Function(BridgeError error) error,
}) {
  return switch (this) {
    AsyncLoading<T>() => loading(),
    AsyncData<T>(value: final v) => data(v),
    AsyncError<T>(error: final e) => error(e),
  };
}