本文整理了Java中io.vavr.control.Either.isLeft()
方法的一些代码示例,展示了Either.isLeft()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Either.isLeft()
方法的具体详情如下:
包路径:io.vavr.control.Either
类名称:Either
方法名:isLeft
[英]Returns whether this Either is a Left.
[中]返回这两者是否为左。
代码示例来源:origin: vavr-io/vavr
@Override
default boolean isEmpty() {
return isLeft();
}
代码示例来源:origin: vavr-io/vavr
@Override
public boolean isEmpty() {
return either.isLeft();
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
public LeftProjection<L, R> orElse(LeftProjection<? extends L, ? extends R> other) {
Objects.requireNonNull(other, "other is null");
return either.isLeft() ? this : (LeftProjection<L, R>) other;
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
public LeftProjection<L, R> orElse(Supplier<? extends LeftProjection<? extends L, ? extends R>> supplier) {
Objects.requireNonNull(supplier, "supplier is null");
return either.isLeft() ? this : (LeftProjection<L, R>) supplier.get();
}
代码示例来源:origin: vavr-io/vavr
/**
* Runs an action in the case this is a projection on a Left value.
*
* @param action an action which consumes a Left value
*/
default void orElseRun(Consumer<? super L> action) {
Objects.requireNonNull(action, "action is null");
if (isLeft()) {
action.accept(getLeft());
}
}
代码示例来源:origin: vavr-io/vavr
default Either<L, R> peekLeft(Consumer<? super L> action) {
Objects.requireNonNull(action, "action is null");
if (isLeft()) {
action.accept(getLeft());
}
return this;
}
代码示例来源:origin: vavr-io/vavr
/**
* Gets the Left value or an alternate value, if the projected Either is a Right.
*
* @param other an alternative value
* @return the left value, if the underlying Either is a Left or else {@code other}
* @throws NoSuchElementException if the underlying either of this LeftProjection is a Right
*/
@Override
public L getOrElse(L other) {
return either.isLeft() ? either.getLeft() : other;
}
代码示例来源:origin: vavr-io/vavr
/**
* Applies the given action to the value if the projected either is a Left. Otherwise nothing happens.
*
* @param action An action which takes a left value
* @return this LeftProjection
*/
@Override
public LeftProjection<L, R> peek(Consumer<? super L> action) {
Objects.requireNonNull(action, "action is null");
if (either.isLeft()) {
action.accept(either.getLeft());
}
return this;
}
代码示例来源:origin: vavr-io/vavr
/**
* Gets the {@code Left} value or throws.
*
* @return the left value, if the underlying {@code Either} is a {@code Left}
* @throws NoSuchElementException if the underlying {@code Either} of this {@code LeftProjection} is a {@code Right}
*/
@Override
public L get() {
if (either.isLeft()) {
return either.getLeft();
} else {
throw new NoSuchElementException("LeftProjection.get() on Right");
}
}
代码示例来源:origin: vavr-io/vavr
/**
* FlatMaps this LeftProjection.
*
* @param mapper A mapper
* @param <U> Component type of the mapped left value
* @return this as {@code LeftProjection<L, U>} if a Right is underlying, otherwise a the mapping result of the left value.
* @throws NullPointerException if {@code mapper} is null
*/
@SuppressWarnings("unchecked")
public <U> LeftProjection<U, R> flatMap(Function<? super L, ? extends LeftProjection<? extends U, R>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
if (either.isLeft()) {
return (LeftProjection<U, R>) mapper.apply(either.getLeft());
} else {
return (LeftProjection<U, R>) this;
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Gets the Left value or an alternate value, if the projected Either is a Right.
*
* @param other a function which converts a Right value to an alternative Left value
* @return the left value, if the underlying Either is a Left or else the alternative Left value provided by
* {@code other} by applying the Right value.
*/
public L getOrElseGet(Function<? super R, ? extends L> other) {
Objects.requireNonNull(other, "other is null");
if (either.isLeft()) {
return either.getLeft();
} else {
return other.apply(either.get());
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Gets the Left value or throws, if the projected Either is a Right.
*
* @param <X> a throwable type
* @param exceptionFunction a function which creates an exception based on a Right value
* @return the left value, if the underlying Either is a Left or else throws the exception provided by
* {@code exceptionFunction} by applying the Right value.
* @throws X if the projected Either is a Right
*/
public <X extends Throwable> L getOrElseThrow(Function<? super R, X> exceptionFunction) throws X {
Objects.requireNonNull(exceptionFunction, "exceptionFunction is null");
if (either.isLeft()) {
return either.getLeft();
} else {
throw exceptionFunction.apply(either.get());
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Filters this right-biased {@code Either} by testing a predicate.
* <p>
*
* @param predicate A predicate
* @return a new {@code Option} instance
* @throws NullPointerException if {@code predicate} is null
*/
default Option<Either<L, R>> filter(Predicate<? super R> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return isLeft() || predicate.test(get()) ? Option.some(this) : Option.none();
}
代码示例来源:origin: vavr-io/vavr
/**
* Maps the left value if the projected Either is a Left.
*
* @param mapper A mapper which takes a left value and returns a value of type U
* @param <U> The new type of a Left value
* @return A new LeftProjection
*/
@SuppressWarnings("unchecked")
@Override
public <U> LeftProjection<U, R> map(Function<? super L, ? extends U> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
if (either.isLeft()) {
return either.mapLeft((Function<L, U>) mapper).left();
} else {
return (LeftProjection<U, R>) this;
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Returns {@code Some} value of type R if this is a right projection of a Right value and the predicate
* applies to the underlying value.
*
* @param predicate A predicate
* @return A new Option
*/
public Option<RightProjection<L, R>> filter(Predicate<? super R> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return either.isLeft() || predicate.test(either.get()) ? Option.some(this) : Option.none();
}
代码示例来源:origin: vavr-io/vavr
/**
* Maps the value of this Either if it is a Left, performs no operation if this is a Right.
*
* <pre>{@code
* import static io.vavr.API.*;
*
* // = Left(2)
* Left(1).mapLeft(i -> i + 1);
*
* // = Right("a")
* Right("a").mapLeft(i -> i + 1);
* }</pre>
*
* @param leftMapper A mapper
* @param <U> Component type of the mapped right value
* @return a mapped {@code Monad}
* @throws NullPointerException if {@code mapper} is null
*/
@SuppressWarnings("unchecked")
default <U> Either<U, R> mapLeft(Function<? super L, ? extends U> leftMapper) {
Objects.requireNonNull(leftMapper, "leftMapper is null");
if (isLeft()) {
return Either.left(leftMapper.apply(getLeft()));
} else {
return (Either<U, R>) this;
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Filters this right-biased {@code Either} by testing a predicate.
* If the {@code Either} is a {@code Right} and the predicate doesn't match, the
* {@code Either} will be turned into a {@code Left} with contents computed by applying
* the filterVal function to the {@code Either} value.
*
* <pre>{@code
* import static io.vavr.API.*;
*
* // = Left("bad: a")
* Right("a").filterOrElse(i -> false, val -> "bad: " + val);
*
* // = Right("a")
* Right("a").filterOrElse(i -> true, val -> "bad: " + val);
* }</pre>
*
* @param predicate A predicate
* @param zero A function that turns a right value into a left value if the right value does not make it through the filter.
* @return an {@code Either} instance
* @throws NullPointerException if {@code predicate} is null
*/
default Either<L,R> filterOrElse(Predicate<? super R> predicate, Function<? super R, ? extends L> zero) {
Objects.requireNonNull(predicate, "predicate is null");
Objects.requireNonNull(zero, "zero is null");
if (isLeft() || predicate.test(get())) {
return this;
} else {
return Either.left(zero.apply(get()));
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public Iterator<L> iterator() {
if (either.isLeft()) {
return Iterator.of(either.getLeft());
} else {
return Iterator.empty();
}
}
代码示例来源:origin: io.vavr/vavr
/**
* Gets the Left value or an alternate value, if the projected Either is a Right.
*
* @param other an alternative value
* @return the left value, if the underlying Either is a Left or else {@code other}
* @throws NoSuchElementException if the underlying either of this LeftProjection is a Right
*/
@Override
public L getOrElse(L other) {
return either.isLeft() ? either.getLeft() : other;
}
代码示例来源:origin: io.vavr/vavr
/**
* Filters this right-biased {@code Either} by testing a predicate.
* <p>
*
* @param predicate A predicate
* @return a new {@code Option} instance
* @throws NullPointerException if {@code predicate} is null
*/
default Option<Either<L, R>> filter(Predicate<? super R> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return isLeft() || predicate.test(get()) ? Option.some(this) : Option.none();
}
内容来源于网络,如有侵权,请联系作者删除!