-
-
Notifications
You must be signed in to change notification settings - Fork 652
Propose Try.toEither(Throwable => L) #2724
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -969,6 +969,15 @@ public void shouldConvertFailureToEitherLeftSupplier() { | |||||||||||||
| assertThat(failure().toEither(() -> "test").isLeft()).isTrue(); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Test | ||||||||||||||
| public void shouldConvertFailureToEitherLeftMapper() { | ||||||||||||||
| final Try<Object> failure = Try.failure(new RuntimeException("a certain value")); | ||||||||||||||
| final Either<Boolean, Object> either = failure.toEither(t -> | ||||||||||||||
| t.getMessage().equals("a certain value") | ||||||||||||||
| ); | ||||||||||||||
| assertThat(either).isEqualTo(Either.left(true)); | ||||||||||||||
|
||||||||||||||
| final Either<Boolean, Object> either = failure.toEither(t -> | |
| t.getMessage().equals("a certain value") | |
| ); | |
| assertThat(either).isEqualTo(Either.left(true)); | |
| final Either<Boolean, Object> either = failure.toEither(Throwable::getMessage); | |
| assertThat(either).isEqualTo(Either.left("a certain value")); |
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.
Sure, sounds much better that way 👍 I also felt a bit weird using Throwable => Boolean as my function where many people would maybe expect that to then be Predicate<Throwable>. I can see also how the equals looks like an assertion.
Main point was just to have a clear expected value returned by the function, so the suggestion sounds great
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.
I'm proposing this change for the documentation so that it is more precise in meaning, because one could legitimately use a
Tryvalue to wrap aThrowableinstance as a success value.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.
I had the same impression that the wording was strange, but I kept this to stay consistent with
toValidation(Throwable => U).I would make this doc change to both of these methods then, since your point applies to both cases.