-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor throwError to orOnErrorThrow #6
Refactor throwError to orOnErrorThrow #6
Conversation
I'm actually not immediately convinced that this is a required change:
Actually my story was that this method originally was |
Well, to be honest I don't see synergy between When I was looking for the Result implementation I found these libraries. Maybe we can inspire from them in picking the right name? |
Not that great source of inspiration... WDYT about |
Hmm. Again for me But to be honset, for me the most relevant name is the same as in WDYT? |
I don't think we've addressed the points:
If you think that the method with current name is actually confusing, then we can move forward and discuss naming, but I would post-pone it for now... |
Well, it is not about confusion, but about DSL your library brings. var result = Result......
return result.throwError(error -> new Exception()); I will not understand it as return me success value or throw an Exception, but rather throw me an Exception in case of error. And you are saying that it will not be hard to learn that it means something different - agree, but why I have to learn it? But on the other hand below code seems to be easier to understand to person who is not familiar with your API. var result = Result......
return result.orElseThrow(error -> new Exception()); It is similar to something I know form JDK, and I don't think it is wrong. All this is just my toughs, and you don't have to apply it. But I think they are reasonable. |
Ok. I think a stand-alone statement is a persuasive argument var result = ...
// ...
return result.throwError(error -> new Exception()); when you see a stand-lone line that says And additionally you seems to be pretty convinced, so lets move forward with naming.
Isn't it exactly what it is? Where is a contradiction in the above description?
I agree. But I have a "but". Sure it's good if we can get something that works the same way as something already in JDK, but |
Ok, I think I understood, why you don't like var value = result.onErrorThrow(error -> ...); it looks confusing. Is the var value = result.orOnErrorThrow(error -> ...); This is a bit mouthful and may sound non-ideal, but it actually conveys the right meaning and is still consistent with other methods... |
5d4e686
to
838f522
Compare
The value |
838f522
to
6784dce
Compare
@@ -392,7 +392,7 @@ static <R, E> Result<R, E> fromOptional(Optional<R> optional, E error) { | |||
* @return the value of this result, when it is a successful result | |||
* @throws X when this is an error result | |||
*/ | |||
default <X extends Exception> R throwError(Function<? super E, X> errorToExceptionConverter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can not simply rename since this is a breaking change and we do not want to release 2.0 that fast after 1.0 release. Please add a deprecated throwError
method, that simply calls orOnErrorThrow
:
/** Throws an exception. Deprecated, use {@link Result#orOnErrorThrow(Function)} instead. */
@Deprecated
default <X extends Exception> R throwError(Function<? super E, X> errorToExceptionConversion)
throws X {
return orOnErrorThrow(errorToExceptionConversion);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -392,7 +392,7 @@ static <R, E> Result<R, E> fromOptional(Optional<R> optional, E error) { | |||
* @return the value of this result, when it is a successful result | |||
* @throws X when this is an error result | |||
*/ | |||
default <X extends Exception> R throwError(Function<? super E, X> errorToExceptionConverter) | |||
default <X extends Exception> R orOnErrorThrow(Function<? super E, X> errorToExceptionConverter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please bump the version in pom.xml: 1.1.5-SNAPSHOT
-> 1.2.0-SNAPSHOT
to record that we are adding new functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
In my opinion `throwError` methods suggest that the error always be thrown. What about changing the name to `orOnErrorThrow`?
6784dce
to
01286f2
Compare
Applied suggested changes. |
Thanks for the high quality contribution! |
In my opinion
throwError
methods suggest that the error always be thrown.What about changing the name to
orOnErrorThrow
?