Remove Maybe.fromOptional(Optional)

This commit is contained in:
Paul Campbell 2018-06-25 07:16:12 +01:00
parent 680b6b8a0d
commit a62b2c8920
2 changed files with 0 additions and 23 deletions

View file

@ -24,8 +24,6 @@ package net.kemitix.mon.maybe;
import lombok.NonNull;
import net.kemitix.mon.Functor;
import java.util.Optional;
/**
* A value that may or may not be present.
*
@ -74,21 +72,4 @@ public interface Maybe<T> extends Functor<T, Maybe<?>>, MaybeStream<T>, MaybeOpt
return just(value);
}
/**
* Create a Maybe from an {@link Optional}.
*
* @param optional the Optional
* @param <T> 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 <T> Maybe<T> fromOptional(final Optional<T> optional) {
return optional.map(Maybe::maybe)
.orElse(nothing());
}
}

View file

@ -85,10 +85,6 @@ 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());
}