maybeMap<R> method

R maybeMap<R>(
  1. {R data(
    1. AsyncData<T> data
    )?,
  2. R error(
    1. AsyncError<T> error
    )?,
  3. R loading(
    1. AsyncLoading<T> loading
    )?,
  4. required R orElse(
      )}
    )

    Perform some actions based on the state of the AsyncValue, or call orElse if the current state was not tested.

    Implementation

    R maybeMap<R>({
      R Function(AsyncData<T> data)? data,
      R Function(AsyncError<T> error)? error,
      R Function(AsyncLoading<T> loading)? loading,
      required R Function() orElse,
    }) {
      return map(
        data: (d) {
          if (data != null) return data(d);
          return orElse();
        },
        error: (d) {
          if (error != null) return error(d);
          return orElse();
        },
        loading: (d) {
          if (loading != null) return loading(d);
          return orElse();
        },
      );
    }