Skip to content

Instantly share code, notes, and snippets.

@DiegoNovati
DiegoNovati / login.kt
Created November 24, 2022 22:41
Error management using the Either monad
// This is how to manage the errors returned by a use case using the Either monad
fun doLogin() {
val params = UseCaseCommonMainLogin.AuthenticationLoginParams(
username = localState.data.username,
password = localState.data.password,
)
useCaseCommonMainLogin.invoke(params, viewModelScope) { result ->
result.fold(::displayError, ::navigateToHome) // 'result' is of type Either<CommonMainFailure, Unit>
}