Sergio Crespo Toubes
05/08/2019, 8:31 AMfun <R> CallK<R>.makeCall(): IO<Response<R>> =
this.async(IO.async()) // Kind<ForIO, Response<R>>
.fix() // IO<Response<R>>
fun <T> IO<Response<T>>.map(): Either<Throwable, T> =
unsafeRunSync()
.unwrapBody(Either.applicativeError())
.fix()
// API
override fun getPosts(authToken: String): Either<Throwable, List<Post>> {
return postsApi.getPosts(authToken).makeCall().map()
}
// PRESENTER
val result: Either<Throwable, List<Post>> = fx{
val (result) = mPostsApi.getPosts(authToken)
result
}