David Corrado
04/21/2022, 3:16 PMfun <T> Result<T>.toDataState(): DataState<T> {
onFailure {
return DataState.failure()
}.onSuccess {
return DataState.success(it)
}
}
But you can not because onFailure and onSuccess is not exhaustive. How have you done this?Casey Brooks
04/21/2022, 3:18 PMResult<T>.fold() for thisephemient
04/21/2022, 3:27 PMreturn result.map {
Data.Success(it)
}.getOrElse {
Data.Failure()
}
which isn't the best choice for this application but you might use something similar if the transform itself can throw and you want to flatten that error (e.g. with mapCatching, recoverCatching)Manish Jain
04/22/2022, 7:20 AM