Opinion on stdlib `kotlin.Result<T>` in kotlin 1.3
See original GitHub issueKotlin 1.3 introduces a new built in type called Result<T>
(docs) in the standard library (stdlib) and in the kotlin
package.
Do you have an opinion on it? It seems to have taken a lot of inspiration from this library, but with one big difference: It doesn’t have an equivalent to flatMap
for operations that return a new Result<T>
. It also doesn’t place any constraints on errors, which are typed as Throwable
.
The immediate inconvenience after upgrading my project to kotlin 1.3 is that I now need to explicitly add the import to use com.github.kittinunf.result.Result
.
The KEEP can be seen here: https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/result.md
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Result - Kotlin Programming Language
A discriminated union that encapsulates a successful outcome with a value of type T or a failure with an arbitrary Throwable exception. Properties....
Read more >KEEP/result.md at master · Kotlin/KEEP - GitHub
The Result class is designed to capture generic failures of Kotlin functions for their latter processing and should be used in general-purpose API...
Read more >Module was compiled with an incompatible version of Kotlin ...
Changing this in file build.gradle solved my problem. From ext.kotlin_version = '1.3.50'. to ext.kotlin_version = '1.6.0'.
Read more >Result type for Kotlin (aka Try monad) : KT-18608 - YouTrack
The proposal is to add a minimal Result type for Kotlin stdlib with the proposed API ... my opinion is yes and I...
Read more >Kotlin (programming language) - Wikipedia
Kotlin has support for the web; by compiling to JavaScript (i.e., Kotlin/JS with the classic back-end, is declared stable since version 1.3), while...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it is too unfortunate that had the standard lib Result (which I will call as std
Result
as opposed to just regularResult
in this repo) covered most of the functionalities, I would have deprecated this library in favor of the standard one.The difference mainly
Result
has some limitations, unable to use as a return type is a huge bummer.Result<Data, IOException>
vsResult<Data, NetworkException>
. With the stdResult
it would end up asResult<Data>
and you have to cast to the right Exception that you wanna use later down the road which is a bummer.With those 2 points, it looks like (fortunately or unfortunately) this
Result
has a reason to stay in the community I guess. 😄 😅It is unfortunate that as of this version, the name is clashing and I am not keen to change the name of this library either. I couldn’t think of a better to deal with this though. If you have some ideas, I am all ears 👂 👂
I would strongly suggest renaming to “Try”, following in the footsteps of Scala and the kotlin Arrow library.
I agree that this library is much more useful than the standard Result monad.