From 4542d82c1a710501d681a87b50826205aac603e0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 21 Jul 2018 22:42:16 +0100 Subject: [PATCH] Rename `Result.invert` as `swap` --- src/main/java/net/kemitix/mon/result/Result.java | 2 +- src/test/java/net/kemitix/mon/ResultTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/kemitix/mon/result/Result.java b/src/main/java/net/kemitix/mon/result/Result.java index 58d7bec..f746df2 100644 --- a/src/main/java/net/kemitix/mon/result/Result.java +++ b/src/main/java/net/kemitix/mon/result/Result.java @@ -123,7 +123,7 @@ public interface Result extends Functor> { * 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 Result> invert(final Maybe> maybeResult) { + static Result> swap(final Maybe> maybeResult) { return maybeResult.orElseGet(() -> Result.ok(null)) .flatMap(value -> Result.ok(Maybe.maybe(value))); } diff --git a/src/test/java/net/kemitix/mon/ResultTest.java b/src/test/java/net/kemitix/mon/ResultTest.java index 2558d69..3805a24 100644 --- a/src/test/java/net/kemitix/mon/ResultTest.java +++ b/src/test/java/net/kemitix/mon/ResultTest.java @@ -300,7 +300,7 @@ public class ResultTest implements WithAssertions { //given final Maybe> justSuccess = Maybe.just(Result.ok(1)); //when - final Result> result = Result.invert(justSuccess); + final Result> 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> justError = Maybe.just(Result.error(exception)); //when - final Result> result = Result.invert(justError); + final Result> result = Result.swap(justError); //then result.match( success -> fail("Not a success"), @@ -327,7 +327,7 @@ public class ResultTest implements WithAssertions { //given final Maybe> nothing = Maybe.nothing(); //when - final Result> result = Result.invert(nothing); + final Result> result = Result.swap(nothing); //then result.match( success -> assertThat(success.toOptional()).isEmpty(), @@ -695,7 +695,7 @@ public class ResultTest implements WithAssertions { final Result 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 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 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) ); }