map<R extends Object?> method

R map<R extends Object?>({
  1. required R initialState(),
  2. required R loadingState(
    1. double? progress
    ),
  3. required R succeedState(
    1. T successObject
    ),
  4. required R failedState(
    1. String? failureMessage,
    2. dynamic exception
    ),
})

Implementation

R map<R extends Object?>({
  required R Function() initialState,
  required R Function(double? progress) loadingState,
  required R Function(T successObject) succeedState,
  required R Function(String? failureMessage, dynamic exception) failedState,
}) {
  final FourStates<T> state = this;
  return switch (state) {
    InitialState<T>() => initialState(),
    LoadingState<T>() => loadingState(state.progress),
    SucceedState<T>() => succeedState(state.successObject),
    FailedState<T>() => failedState(state.failureMessage, state.exceptionObject),
  };
}