Rename Result.invert as swap

This commit is contained in:
Paul Campbell 2018-07-21 22:42:16 +01:00
parent b80650b6ae
commit 4542d82c1a
2 changed files with 7 additions and 7 deletions

View file

@ -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)));
}

View file

@ -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(),