arrow-kt / arrow-integrations

Λrrow Integrations is part of Λrrow, a functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
27 stars 6 forks source link

Add adapter for Either<ErrorBody, ResponseBody> #26

Closed LordRaydenMK closed 4 years ago

LordRaydenMK commented 4 years ago

Supports declaring your Retrofit interface like:

interface SuspedApiClientTest {

  @GET("/")
  suspend fun getEither(): Either<ErrorMock, ResponseMock>

  @GET("/")
  suspend fun getResponseE(): ResponseE<ErrorMock, ResponseMock>
}

note: ResponseE is the equivalent of retrofit.Response but using Either for the body (left in case of HTTP error, right in case of success).

Problems: There is a null check for the body, meaning it errors on 204 (No Content) because the body is null in that case.

LordRaydenMK commented 4 years ago

hey @leandroBorgesFerreira

I extracted a function in ArrowCallAdapterFactory for the duplicated code.

For the ArrowEitherCallAdapter and ArrowEitherECallAdapter the code looks similar, but the types are all different e.g. Call<Either<E, R>> VS Call<ResponseE<E, R>> the Callback type is also different, so I would have to parametrize a lot of things. That would make the code harder to read IMO.

I'm a bit out of the scene, what is the motivation of the PR? I think Async already has ways to handle exceptions and Either is normally used for synchronous calls.

this works with suspend + Either meaning it isomorphic to IO<E, A> and can be used for async calls.