map<R> method

R map<R>({
  1. required R onLoading(),
  2. required R onDone(
    1. T? data
    ),
  3. required R onError(
    1. E? error
    ),
  4. required R onInit(),
})

Declare methods base on fetchingStatus

all state methods are required return type R need to be the same on all methods

Implementation

R map<R>({
  required R Function() onLoading,
  required R Function(T? data) onDone,
  required R Function(E? error) onError,
  required R Function() onInit,
}) {
  switch (fetchingStatus) {
    case FetchingStatus.init:
      return onInit();
    case FetchingStatus.loading:
      return onLoading();
    case FetchingStatus.done:
      return onDone(data);
    case FetchingStatus.error:
      return onError(error);
  }
}