Remove Maybe.fromOptional(Optional)
This commit is contained in:
parent
680b6b8a0d
commit
a62b2c8920
2 changed files with 0 additions and 23 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue