Remove Maybe.fromOptional(Optional)
This commit is contained in:
parent
3496fa0972
commit
7a150066a9
2 changed files with 1 additions and 25 deletions
|
@ -24,7 +24,6 @@ package net.kemitix.mon.maybe;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import net.kemitix.mon.Functor;
|
import net.kemitix.mon.Functor;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,22 +70,6 @@ public interface Maybe<T> extends Functor<T, Maybe<?>>, MaybeStream<T>, MaybeOpt
|
||||||
return new Just<>(value);
|
return new 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<R> Maybe<R> map(Function<T, R> f);
|
<R> Maybe<R> map(Function<T, R> f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static net.kemitix.mon.maybe.Maybe.just;
|
import static net.kemitix.mon.maybe.Maybe.*;
|
||||||
import static net.kemitix.mon.maybe.Maybe.maybe;
|
|
||||||
import static net.kemitix.mon.maybe.Maybe.nothing;
|
|
||||||
|
|
||||||
public class MaybeTest implements WithAssertions {
|
public class MaybeTest implements WithAssertions {
|
||||||
|
|
||||||
|
@ -85,15 +83,10 @@ public class MaybeTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromOptional() {
|
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.of(1).map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(just(1));
|
||||||
assertThat(Optional.empty().map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(nothing());
|
assertThat(Optional.empty().map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void peek() {
|
public void peek() {
|
||||||
final AtomicInteger ref = new AtomicInteger(0);
|
final AtomicInteger ref = new AtomicInteger(0);
|
||||||
|
|
Loading…
Reference in a new issue