question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Opinion on stdlib `kotlin.Result<T>` in kotlin 1.3

See original GitHub issue

Kotlin 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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kittinunfcommented, Mar 25, 2019

Yes, it is too unfortunate that had the standard lib Result (which I will call as std Result as opposed to just regular Result in this repo) covered most of the functionalities, I would have deprecated this library in favor of the standard one.

The difference mainly

  1. std Result has some limitations, unable to use as a return type is a huge bummer.
  2. Have a constraint type Error is a good thing. For me personally, it is a huge difference between Result<Data, IOException> vs Result<Data, NetworkException>. With the std Result it would end up as Result<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 👂 👂

2reactions
ragnesecommented, Dec 5, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found