maybeMap<R extends Object?> method

R maybeMap<R extends Object?>({
  1. required R orElse(),
  2. R initialState(
    1. InitialState<T> initialState
    )?,
  3. R loadingState(
    1. LoadingState<T> loadingState
    )?,
  4. R succeedState(
    1. SucceedState<T> succeedState
    )?,
  5. R failedState(
    1. FailedState<T> failedState
    )?,
})

Implementation

R maybeMap<R extends Object?>({
  required R Function() orElse,
  R Function(InitialState<T> initialState)? initialState,
  R Function(LoadingState<T> loadingState)? loadingState,
  R Function(SucceedState<T> succeedState)? succeedState,
  R Function(FailedState<T> failedState)? failedState,
}) {
  final FourStates<T> state = this;
  return switch (state) {
    InitialState<T>() => initialState == null ? orElse() : initialState(state),
    LoadingState<T>() => loadingState == null ? orElse() : loadingState(state),
    SucceedState<T>() => succeedState == null ? orElse() : succeedState(state),
    FailedState<T>() => failedState == null ? orElse() : failedState(state),
  };
}