diff --git a/CHANGELOG b/CHANGELOG index 7851cc2..d55eac1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ CHANGELOG ========= +0.11.0 + +* Rename `Result.maybeThen()` as `Result.flatMapMaybe()` + 0.10.0 ------ diff --git a/src/main/java/net/kemitix/mon/result/Result.java b/src/main/java/net/kemitix/mon/result/Result.java index 9b82836..829fd64 100644 --- a/src/main/java/net/kemitix/mon/result/Result.java +++ b/src/main/java/net/kemitix/mon/result/Result.java @@ -129,7 +129,7 @@ public interface Result extends Functor> { * @param the type of the updated Result * @return a new Maybe within a Result */ - static Result> maybeThen(Result> maybeResult, Function, Result>> f) { + static Result> flatMapMaybe(Result> maybeResult, Function, Result>> f) { return maybeResult.flatMap(f); } diff --git a/src/test/java/net/kemitix/mon/ResultTest.java b/src/test/java/net/kemitix/mon/ResultTest.java index 8956906..edda0e3 100644 --- a/src/test/java/net/kemitix/mon/ResultTest.java +++ b/src/test/java/net/kemitix/mon/ResultTest.java @@ -605,24 +605,24 @@ public class ResultTest implements WithAssertions { } @Test - public void okayJust_whenMaybeThen_whereOkayJust_thenIsOkayJust() { + public void okayJust_whenFlatMapMaybe_whereOkayJust_thenIsOkayJust() { //given final Result> okJust = Result.ok(Maybe.just(1)); //when - final Result> result = Result.maybeThen(okJust, mv -> Result.ok(Maybe.just(2))); + final Result> result = Result.flatMapMaybe(okJust, maybe -> Result.ok(maybe.flatMap(v -> Maybe.just("2")))); //then result.match( - success -> assertThat(success.toOptional()).contains(2), + success -> assertThat(success.toOptional()).contains("2"), error -> fail("Not an error") ); } @Test - public void okayJust_whenMaybeThen_whereOkayNothing_thenIsOkayNothing() { + public void okayJust_whenFlatMapMaybe_whereOkayNothing_thenIsOkayNothing() { //given final Result> okJust = Result.ok(Maybe.just(1)); //when - final Result> result = Result.maybeThen(okJust, v -> Result.ok(Maybe.nothing())); + final Result> result = Result.flatMapMaybe(okJust, maybe -> Result.ok(maybe.flatMap(v -> Maybe.nothing()))); //then result.match( success -> assertThat(success.toOptional()).isEmpty(), @@ -631,12 +631,12 @@ public class ResultTest implements WithAssertions { } @Test - public void okayJust_whenMaybeThen_whereError_thenIsError() { + public void okayJust_whenFlatMapMaybe_whereError_thenIsError() { //given final Result> okJust = Result.ok(Maybe.just(1)); final RuntimeException exception = new RuntimeException(); //when - final Result> result = Result.maybeThen(okJust, v -> Result.error(exception)); + final Result> result = Result.flatMapMaybe(okJust, v -> Result.error(exception)); //then result.match( success -> fail("Not a success"), @@ -645,27 +645,27 @@ public class ResultTest implements WithAssertions { } @Test - public void okayNothing_whenMaybeThen_thenDoNotApply() { + public void okayNothing_whenFlatMapMaybe_thenDoNotApply() { //given final Result> okNothing = Result.ok(Maybe.nothing()); //when - final Result> result = Result.maybeThen(okNothing, v -> Result.ok(Maybe.just(2))); + final Result> result = Result.flatMapMaybe(okNothing, maybe -> Result.ok(maybe.flatMap(v -> Maybe.just("2")))); //then - okNothing.match( + result.match( success -> assertThat(success.toOptional()).isEmpty(), error -> fail("Not an error") ); } @Test - public void error_whenMaybeThen_thenDoNotApply() { + public void error_whenFlatMapMaybe_thenDoNotApply() { //given final RuntimeException exception = new RuntimeException(); final Result> maybeResult = Result.error(exception); //when - final Result> result = Result.maybeThen(maybeResult, v -> Result.ok(Maybe.just(2))); + final Result> result = Result.flatMapMaybe(maybeResult, maybe -> Result.ok(maybe.flatMap(v -> Maybe.just("2")))); //then - maybeResult.match( + result.match( success -> fail("Not a success"), error -> assertThat(error).isSameAs(exception) );