map<R> method

AsyncValue<R> map<R>(
  1. R mapper(
    1. T data
    )
)

Maps the data type of this AsyncValue to R while preserving the loading and error state. This can be used to add additional data to the AsyncValue.

Implementation

AsyncValue<R> map<R>(R Function(T data) mapper) {
  return switch (this) {
    AsyncData<T> curr => AsyncData<R>._(mapper(curr.data)),
    AsyncLoading<T> curr =>
      AsyncLoading<R>._(curr.data != null ? mapper(curr.data as T) : null),
    AsyncError<T> curr => AsyncError<R>._(curr.error, curr.stackTrace,
        curr.data != null ? mapper(curr.data as T) : null),
  };
}