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
|
* 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.
|
* 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))
|
return maybeResult.orElseGet(() -> Result.ok(null))
|
||||||
.flatMap(value -> Result.ok(Maybe.maybe(value)));
|
.flatMap(value -> Result.ok(Maybe.maybe(value)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ public class ResultTest implements WithAssertions {
|
||||||
//given
|
//given
|
||||||
final Maybe<Result<Integer>> justSuccess = Maybe.just(Result.ok(1));
|
final Maybe<Result<Integer>> justSuccess = Maybe.just(Result.ok(1));
|
||||||
//when
|
//when
|
||||||
final Result<Maybe<Integer>> result = Result.invert(justSuccess);
|
final Result<Maybe<Integer>> result = Result.swap(justSuccess);
|
||||||
//then
|
//then
|
||||||
result.match(
|
result.match(
|
||||||
success -> assertThat(success.toOptional()).contains(1),
|
success -> assertThat(success.toOptional()).contains(1),
|
||||||
|
@ -314,7 +314,7 @@ public class ResultTest implements WithAssertions {
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Maybe<Result<Object>> justError = Maybe.just(Result.error(exception));
|
final Maybe<Result<Object>> justError = Maybe.just(Result.error(exception));
|
||||||
//when
|
//when
|
||||||
final Result<Maybe<Object>> result = Result.invert(justError);
|
final Result<Maybe<Object>> result = Result.swap(justError);
|
||||||
//then
|
//then
|
||||||
result.match(
|
result.match(
|
||||||
success -> fail("Not a success"),
|
success -> fail("Not a success"),
|
||||||
|
@ -327,7 +327,7 @@ public class ResultTest implements WithAssertions {
|
||||||
//given
|
//given
|
||||||
final Maybe<Result<Integer>> nothing = Maybe.nothing();
|
final Maybe<Result<Integer>> nothing = Maybe.nothing();
|
||||||
//when
|
//when
|
||||||
final Result<Maybe<Integer>> result = Result.invert(nothing);
|
final Result<Maybe<Integer>> result = Result.swap(nothing);
|
||||||
//then
|
//then
|
||||||
result.match(
|
result.match(
|
||||||
success -> assertThat(success.toOptional()).isEmpty(),
|
success -> assertThat(success.toOptional()).isEmpty(),
|
||||||
|
|
Loading…
Reference in a new issue