kittinunf / Result

The modelling for success/failure of operations in Kotlin and KMM (Kotlin Multiplatform Mobile)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better java support

yoavst opened this issue · comments

Since it is based on extension methods, it doesn't play well on Java.

Well, unlike Fuel, I don't think Result should support Java. It aims at the beginning that it was meant to support Kotlin and solely Kotlin.

I'm not requesting for a lot, just a way to know if it is failed (only possible in try catch of get() or component2()) and getting the exception, from Java.

Fair enough. I haven't used Java for a big while for I wouldn't know exactly what really Java client wants. If you have some proposal and it doesn't alter Result too much, I am happy to accept it.

I'm not interested in Java support but if this is meant solely to target Kotlin I'm wondering why the errors in Result require Exception as a base class as opposed to Kotlin's Throwable?

Good point! Thanks for asking. When I designed this Result class (which was kinda long ago), I considered Throwableas well. However, I dropped it at the last minute in favor of Exception.

There is a reason for it though. If I use Throwable, client could use Error for a Failure case in Result which is not semantically what I want. I prefer the Failure case to be an error state which is recoverable, that is mostly like be represented by Exception as opposed to a non-recoverable (serious) like Error.

If you could come up with a use case which is likely better to represent as Throwable, I am happy to discuss.