Hi, it’s me once more :stuck_out_tongue: As I am w...
# arrow
h
Hi, it’s me once more 😛 As I am writing https://github.com/arrow-kt/arrow-integrations/pull/28, I simultaneously write code for my sample arrow project and encountered case. Do you know if there is any way to “hack” this, or another contrubution 😄 is needed 😛 More will be in comment not to throw too much code in here 😛
I have retrofit repository with Tagless (IO) integration (from PR above):
Copy code
@Multipart
  @POST("/calculate")
  fun calculate(@Part file: MultipartBody.Part): IO<Nothing, FaceVectorsDto>
and error ADT:
Copy code
sealed class Error
...
sealed class RepositoryError : Error()
class ExternalFailure(val error: Throwable): RepositoryError()
and wish to handle exception flow into domain error
ExternalFailure
I have code in service calling above retrofit code:
Copy code
override fun calculatePhoto(photo: ByteArray): IO<RepositoryError, FaceVectors> =
    IO.fx<RepositoryError, FaceVectors> {
      val photoPart = createPhotoPart(photo)
      val faceVectorsDto = !recognitionClient
        .calculate(photoPart)
        .handleErrorWith({ IO.raiseError(ExternalFailure(it)) }, ::identity) //1*
      faceVectorsDto.toDomainUnsafe()
    }
// some space to get small breath 😛 In line with
//1*
I get type mismatch error in Intellij syntax highlightning it is because
handleErrorWith
have signature:
Copy code
fun <E, A, E2 : E> IOOf<E, A>.handleErrorWith(f: (Throwable) -> IOOf<E2, A>, fe: (E) -> IOOf<E2, A>): IO<E2, A>
And if
E
is
Nothing
(getting it from retrofit client), then
E2
must be
Nothing
too, because NOTHING 😛 is below
Nothing
in the hieratchy of inheritance. // and another some space for some breath 😉 Simple fix will be making
E2
independent from
E
Other
handleErrorWith
is even worse for this case, because it has fixed
IO<Nothing, A>
type in arrow code Is there maybe another way to handle such case?
p
checking
😄 1
h
If it will be easier for you, I can push that code to github
p
I have a guess, this is because the current encoding requires subtyping and it shouldn’t be necessary
nah it isn’t fixed there either
so what you can do with what’s in master is
mapError
then
handleErrorWith
mapError doesn’t require a subtyping relationship
h
It looks not so good but works:
Copy code
val faceVectorsDto = !recognitionClient
        .calculate(photoPart)
        .mapError<Nothing, FaceVectorsDto, RepositoryError>(::identity)
        .handleErrorWith({ IO.raiseError(ExternalFailure(it)) }, { IO.raiseError(it) })
Thanks, also for commenting in ticket 😄
👌🏼 1