map<R extends Object?> method

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

Implementation

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