fold<R> method

R fold<R>({
  1. required R onFetchFailure(
    1. Object error,
    2. StackTrace stackTrace
    ),
  2. required R onFetchSuccess(
    1. Content data
    ),
  3. required R onRefreshFailure(
    1. Object error,
    2. StackTrace stackTrace
    ),
  4. required R onRefreshSuccess(
    1. Content data
    ),
})

Fold all cases into single value

Implementation

R fold<R>({
  required R Function(Object error, StackTrace stackTrace) onFetchFailure,
  required R Function(Content data) onFetchSuccess,
  required R Function(Object error, StackTrace stackTrace) onRefreshFailure,
  required R Function(Content data) onRefreshSuccess,
}) {
  final self = this;
  if (self is _FetchFailure<Content>) {
    return onFetchFailure(self.error, self.stackTrace);
  }
  if (self is _FetchSuccess<Content>) {
    return onFetchSuccess(self.content);
  }
  if (self is _RefreshFailure<Content>) {
    return onRefreshFailure(self.error, self.stackTrace);
  }
  if (self is _RefreshSuccess<Content>) {
    return onRefreshSuccess(self.content);
  }
  throw StateError('Unknown type $self');
}