Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve of function #38

Merged
merged 2 commits into from
Jul 13, 2018
Merged

Improve of function #38

merged 2 commits into from
Jul 13, 2018

Conversation

kittinunf
Copy link
Owner

@kittinunf kittinunf commented Jul 10, 2018

What's in this PR?

This PR aims to improve usage of, so that it can be specified Exception type by the client.

The new signature is

fun <V : Any, E: Exception> of(f: () -> V): Result<V, E>

@kittinunf kittinunf changed the title Improve on of function Improve of function Jul 10, 2018
@bohsen
Copy link

bohsen commented Jul 10, 2018

@kittinunf I was wondering if you've seen the proposal for Kotlin to provide a Standard Library class to encapsulate successful or failed function execution? Just wanted to make you aware of it for future work.
Love your library and the API. I would love to see an API like this in Kotlin actually.

@kittinunf
Copy link
Owner Author

kittinunf commented Jul 11, 2018

@bohsen

To me, the idea of promoting E as a full type has very strong benefits. It makes you aware that Result<Foo, Exception1> and Result<Foo, Exception2> are distinct and hence they should be handled differently. And it also make the API that interacts with Error really shine like mapError and flatmapError.

If the proposal got accepted, it is good thing. However, as long as this library provides a direct benefit which the proposal couldn't, it might be best to use it differently.

@kittinunf
Copy link
Owner Author

Let's merge this. ;)

@kittinunf kittinunf merged commit 5e3e9de into master Jul 13, 2018
@kittinunf kittinunf deleted the kv/use-e-instead-of-exception branch July 13, 2018 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants