fold method

void fold({
  1. required void onSuccess(
    1. T
    ),
  2. required void onError(
    1. Exception
    ),
  3. void onLoading()?,
})

Implementation

void fold(
    {required void Function(T) onSuccess,
      required void Function(Exception) onError,
      void Function()? onLoading}) {
  switch (this) {
    case ResourceEmpty():
      {
        break;
      }
    case ResourceSuccess():
      {
        onSuccess.call(data as T);
        break;
      }
    case ResourceError():
      {
        onError.call(failure!);
        break;
      }
    case ResourceLoading():
      {
        if(onLoading != null){
          onLoading();
        }
        break;
      }
  }
}