maybeMap<R> method

R maybeMap<R>({
  1. required R orElse(),
  2. R ready(
    1. ResourceReady<T> ready
    )?,
  3. R error(
    1. ResourceError<T> error
    )?,
  4. R loading(
    1. ResourceLoading<T> loading
    )?,
})

Perform some actions based on the state of the ResourceState, or call orElse if the current state is not considered.

Implementation

R maybeMap<R>({
  required R Function() orElse,
  R Function(ResourceReady<T> ready)? ready,
  R Function(ResourceError<T> error)? error,
  R Function(ResourceLoading<T> loading)? loading,
}) {
  return map(
    ready: (r) {
      if (ready != null) return ready(r);
      return orElse();
    },
    error: (d) {
      if (error != null) return error(d);
      return orElse();
    },
    loading: (l) {
      if (loading != null) return loading(l);
      return orElse();
    },
  );
}