-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Propose Try.toEither(Throwable => L) #2724
base: version/1.x
Are you sure you want to change the base?
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)); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably replace the test code in a way that limits the number of comparisons to one, which would be the one in the assertion itself.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Main point was just to have a clear expected value returned by the function, so the suggestion sounds great |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
// -- toValidation | ||||||||||||||
|
||||||||||||||
|
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
Try
value to wrap aThrowable
instance 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.