Leandro Borges Ferreira
06/24/2018, 11:57 PMfun fetchAllPayments(): Reader<PaymentsDeps, IO<List<Payment>>> =
ReaderApi.ask<PaymentsDeps>()
.map { deps ->
IO.async<List<Payment>> { either ->
async {
either(queryForPayments(deps.apiClient).toEither())
}
}
}
fun queryForPayments(apiClient: ApiClient): Try<List<Payment>> =
Try { apiClient.getPayments() }
I would just like to aggregate a log result in my second function. Like this:
fun queryForPayments(apiClient: ApiClient): Try<WriterT<String, List<Payment>>> =
Try { apiClient.getPayments().put("The computation worked just fine!") }
This would also work:
fun queryForPayments(apiClient: ApiClient): Try<Pair<String, List<Payment>>> =
Try { apiClient.getPayments() to "The computation worked just fine!" }
But it looks less elegant.
By passing the log as a result of the function, I don't have to cause side effects in the function, then I can print the log results in a later moment.