Skip to content

Instantly share code, notes, and snippets.

@LloydBlv
Created February 3, 2024 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LloydBlv/9bad5a2240ffcba45e2062c0e9c55b94 to your computer and use it in GitHub Desktop.
Save LloydBlv/9bad5a2240ffcba45e2062c0e9c55b94 to your computer and use it in GitHub Desktop.
class PricesViewModel @Inject constructor(
errorFormatter: dagger.Lazy<ErrorFormatter>,
pricesUseCase: dagger.Lazy<GetPricesUseCase>
): ViewModel() {
val state = pricesUseCase.get().invoke()
.map {
State.Success(it)
}
.catch {
val error = errorFormatter.get().format(it)
emit(State.Error(error))
}.stateInDefault(viewModelScope, State.Loading)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment