whenData<R> method

AsyncValue<R> whenData<R>(
  1. R cb(
    1. T value
    )
)

Shorthand for when to handle only the data case.

Implementation

AsyncValue<R> whenData<R>(R Function(T value) cb) {
  return when(
    data: (value) {
      try {
        return AsyncValue.data(cb(value));
      } catch (err, stack) {
        return AsyncValue.error(err, stack);
      }
    },
    loading: () => const AsyncValue.loading(),
    error: (err, stack) => AsyncValue.error(err, stack),
  );
}