From 7a150066a91c41dcd506a79531516c0852232bed Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 25 Jun 2018 21:59:24 +0100 Subject: [PATCH] Remove Maybe.fromOptional(Optional) --- src/main/java/net/kemitix/mon/maybe/Maybe.java | 17 ----------------- src/test/java/net/kemitix/mon/MaybeTest.java | 9 +-------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/main/java/net/kemitix/mon/maybe/Maybe.java b/src/main/java/net/kemitix/mon/maybe/Maybe.java index 51b4584..744068c 100644 --- a/src/main/java/net/kemitix/mon/maybe/Maybe.java +++ b/src/main/java/net/kemitix/mon/maybe/Maybe.java @@ -24,7 +24,6 @@ package net.kemitix.mon.maybe; import lombok.NonNull; import net.kemitix.mon.Functor; -import java.util.Optional; import java.util.function.Function; /** @@ -71,22 +70,6 @@ public interface Maybe extends Functor>, MaybeStream, MaybeOpt return new Just<>(value); } - /** - * Create a Maybe from an {@link Optional}. - * - * @param optional the Optional - * @param the type of the Optional - * @return a Maybe - * @deprecated need to find a better way of converting an Optional to a Maybe, but - * without having to pass the Optional as a parameter - * Try: Optional.of(1).map(Maybe::just).orElse(Maybe::nothing) - */ - @Deprecated - static Maybe fromOptional(final Optional optional) { - return optional.map(Maybe::maybe) - .orElse(nothing()); - } - @Override Maybe map(Function f); } diff --git a/src/test/java/net/kemitix/mon/MaybeTest.java b/src/test/java/net/kemitix/mon/MaybeTest.java index 4f3b31b..12ec238 100644 --- a/src/test/java/net/kemitix/mon/MaybeTest.java +++ b/src/test/java/net/kemitix/mon/MaybeTest.java @@ -10,9 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.stream.Stream; -import static net.kemitix.mon.maybe.Maybe.just; -import static net.kemitix.mon.maybe.Maybe.maybe; -import static net.kemitix.mon.maybe.Maybe.nothing; +import static net.kemitix.mon.maybe.Maybe.*; public class MaybeTest implements WithAssertions { @@ -85,15 +83,10 @@ public class MaybeTest implements WithAssertions { @Test public void fromOptional() { - // deprecated methods - assertThat(Maybe.fromOptional(Optional.of(1))).isEqualTo(just(1)); - assertThat(Maybe.fromOptional(Optional.empty())).isEqualTo(nothing()); - // recommended alternative assertThat(Optional.of(1).map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(just(1)); assertThat(Optional.empty().map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(nothing()); } - @Test public void peek() { final AtomicInteger ref = new AtomicInteger(0);