Rename Result.invert
as swap
This commit is contained in:
parent
b80650b6ae
commit
4542d82c1a
2 changed files with 7 additions and 7 deletions
|
@ -123,7 +123,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
|||
* original Maybe. If the original Maybe is Nothing, the Result will contain Nothing. If the original Result was an
|
||||
* error, then the Result will also be an error.
|
||||
*/
|
||||
static <T> Result<Maybe<T>> invert(final Maybe<Result<T>> maybeResult) {
|
||||
static <T> Result<Maybe<T>> swap(final Maybe<Result<T>> maybeResult) {
|
||||
return maybeResult.orElseGet(() -> Result.ok(null))
|
||||
.flatMap(value -> Result.ok(Maybe.maybe(value)));
|
||||
}
|
||||
|
|
|
@ -300,7 +300,7 @@ public class ResultTest implements WithAssertions {
|
|||
//given
|
||||
final Maybe<Result<Integer>> justSuccess = Maybe.just(Result.ok(1));
|
||||
//when
|
||||
final Result<Maybe<Integer>> result = Result.invert(justSuccess);
|
||||
final Result<Maybe<Integer>> result = Result.swap(justSuccess);
|
||||
//then
|
||||
result.match(
|
||||
success -> assertThat(success.toOptional()).contains(1),
|
||||
|
@ -314,7 +314,7 @@ public class ResultTest implements WithAssertions {
|
|||
final RuntimeException exception = new RuntimeException();
|
||||
final Maybe<Result<Object>> justError = Maybe.just(Result.error(exception));
|
||||
//when
|
||||
final Result<Maybe<Object>> result = Result.invert(justError);
|
||||
final Result<Maybe<Object>> result = Result.swap(justError);
|
||||
//then
|
||||
result.match(
|
||||
success -> fail("Not a success"),
|
||||
|
@ -327,7 +327,7 @@ public class ResultTest implements WithAssertions {
|
|||
//given
|
||||
final Maybe<Result<Integer>> nothing = Maybe.nothing();
|
||||
//when
|
||||
final Result<Maybe<Integer>> result = Result.invert(nothing);
|
||||
final Result<Maybe<Integer>> result = Result.swap(nothing);
|
||||
//then
|
||||
result.match(
|
||||
success -> assertThat(success.toOptional()).isEmpty(),
|
||||
|
@ -695,7 +695,7 @@ public class ResultTest implements WithAssertions {
|
|||
final Result<Integer> result11 = result1.reduce(result10, (a, b) -> a + b);
|
||||
//then
|
||||
result11.match(
|
||||
success->fail("Not a success"),
|
||||
success -> fail("Not a success"),
|
||||
error -> assertThat(error).isSameAs(exception)
|
||||
);
|
||||
}
|
||||
|
@ -710,7 +710,7 @@ public class ResultTest implements WithAssertions {
|
|||
final Result<Integer> result11 = result1.reduce(result10, (a, b) -> a + b);
|
||||
//then
|
||||
result11.match(
|
||||
success->fail("Not a success"),
|
||||
success -> fail("Not a success"),
|
||||
error -> assertThat(error).isSameAs(exception)
|
||||
);
|
||||
}
|
||||
|
@ -726,7 +726,7 @@ public class ResultTest implements WithAssertions {
|
|||
final Result<Integer> result11 = result1.reduce(result10, (a, b) -> a + b);
|
||||
//then
|
||||
result11.match(
|
||||
success->fail("Not a success"),
|
||||
success -> fail("Not a success"),
|
||||
error -> assertThat(error).isSameAs(exception1)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue