jean
10/29/2021, 7:16 AMdata class GetUserImageContext(val apiClient: ApiClient)
typealias GetUserImage = suspend GetUserImageContext.(path: String) -> Either<ApiError, UserImage>
fun getUserImage(): GetUserImage = { path ->
try {
// some executiuon
Either.Right(image)
} catch(e: Exception) {
Either.Left(ApiError.SomethingWentWrong)
}
}
This suits me well for unit testing but the problem comes where a function is composed of several like that one. The context object ends up containing too many things :
data class GetUserContext(
val getUserImageContext: GetUserImageContext,
val getUserImage: GetUserImage,
// keeps on going based on the functions needed for building the final object
)
...
// I need both the context object and the alias object to be able to get the final value I want
val image = getUserImage(getUserImageContext, "/some/path")
I did watch some of the video on youtube talking about this recommended the “Context” approach but they are ~3 years old.
Is there a better way to approach this now?jean
11/01/2021, 9:34 AMPeter
11/01/2021, 5:43 PMPeter
11/01/2021, 5:44 PMEither.catch { }
?jean
11/02/2021, 8:43 AMEither.catch
that’s a nice complement to other features I use 🙂simon.vergauwen
11/02/2021, 10:29 AMjean
11/02/2021, 11:50 AM