Map that throws?
macduy opened this issue · comments
Mac Duy Hai commented
Hi, I was surprised to find that this code would not print "Error":
val result = Result<Int, Exception>.of(0)
result.map {
transform(it) // transform throws
}.failure {
print("Error")
}
fun transform(i: Int) {
throw Exception()
}
It looks like map does not expect to handle errors. What I had to do instead was:
val result = Result<Int, Exception>.of(0)
result.flatMap {
Result.of {
transform(it)
}
}.failure {
print("Error")
}
which looks less elegant. More importantly, in the first case, there is no error shown anywhere so it's difficult to debug.
Kittinun Vantasin commented
Hmm, I think this is an overlook from me. I very much agree with you. I will try to address this in the next version.
Mac Duy Hai commented
Thanks Kittinun!
Kittinun Vantasin commented
This should be addressed by #30. Thanks for reporting this! :)
Mac Duy Hai commented
Ah that's awesome. Thank you, great work!