maybeWhen<R> method

R maybeWhen<R>({
  1. R notInitialized()?,
  2. R inProgress(
    1. CancelableOperation<T> operation
    )?,
  3. R ready(
    1. T value
    )?,
  4. R failed(
    1. Object exception
    )?,
  5. required R orElse(),
})

Implementation

R maybeWhen<R>({
  R Function()? notInitialized,
  R Function(CancelableOperation<T> operation)? inProgress,
  R Function(T value)? ready,
  R Function(Object exception)? failed,
  required R Function() orElse,
}) {
  final value = this;
  if (value is ComputedStateValueNotInitialized && notInitialized != null) return notInitialized();
  if (value is ComputedStateValueInProgress<T> && inProgress != null) {
    return inProgress(value.operation);
  }
  if (value is ComputedStateValueReady<T> && ready != null) return ready(value.value);
  if (value is ComputedStateValueFailed && failed != null) return failed(value.exception);
  return orElse();
}