/** True if it's right. */ default boolean isRight() { return !isLeft(); }
/** True if it's right. */ public final boolean isRight() { return !isLeft(); }
/** Performs the given action if this is a Left. */ public final void ifLeft(Consumer<? super L> consumer) { requireNonNull(consumer); if (isLeft()) { consumer.accept(getLeft()); } }
/** Performs the given action if this is a Left. */ public final void ifLeft(Consumer<? super L> consumer) { if (isLeft()) { consumer.accept(getLeft()); } }
/** Performs the given action if this is a Left. */ default void ifLeft(Consumer<? super L> consumer) { if (isLeft()) { consumer.accept(getLeft()); } }
/** Applies either the left or the right function as appropriate. */ public final <T> T fold(Function<? super L, ? extends T> left, Function<? super R, ? extends T> right) { requireNonNull(left); requireNonNull(right); if (isLeft()) { return left.apply(getLeft()); } else { return right.apply(getRight()); } }
/** Applies either the left or the right function as appropriate. */ default <T> T fold(Function<? super L, ? extends T> left, Function<? super R, ? extends T> right) { if (isLeft()) { return left.apply(getLeft()); } else { return right.apply(getRight()); } }
/** Accepts either the left or the right consumer as appropriate. */ public final void accept(Consumer<? super L> left, Consumer<? super R> right) { requireNonNull(left); requireNonNull(right); if (isLeft()) { left.accept(getLeft()); } else { right.accept(getRight()); } }
/** Accepts either the left or the right consumer as appropriate. */ public final void accept(Consumer<? super L> left, Consumer<? super R> right) { if (isLeft()) { left.accept(getLeft()); } else { right.accept(getRight()); } }
@SuppressWarnings("unchecked") public final <T> Either<T, R> mapLeft(Function<? super L, ? extends T> mapper) { requireNonNull(mapper); if (isLeft()) { return Either.createLeft(mapper.apply(getLeft())); } else { return (Either<T, R>) this; } }
/** Applies either the left or the right function as appropriate. */ public final <T> T fold(Function<? super L, ? extends T> left, Function<? super R, ? extends T> right) { if (isLeft()) { return left.apply(getLeft()); } else { return right.apply(getRight()); } }
@SuppressWarnings("unchecked") public final <T> Either<L, T> mapRight(Function<? super R, ? extends T> mapper) { requireNonNull(mapper); if (isLeft()) { return (Either<L, T>) this; } else { return Either.createRight(mapper.apply(getRight())); } }
/** Accepts either the left or the right consumer as appropriate. */ default void accept(Consumer<? super L> left, Consumer<? super R> right) { if (isLeft()) { left.accept(getLeft()); } else { right.accept(getRight()); } }
@SuppressWarnings("unchecked") default <T> Either<T, R> mapLeft(Function<? super L, ? extends T> mapper) { if (isLeft()) { return Either.createLeft(mapper.apply(getLeft())); } else { return (Either<T, R>) this; } }
@SuppressWarnings("unchecked") public final <T> Either<T, R> mapLeft(Function<? super L, ? extends T> mapper) { if (isLeft()) { return Either.createLeft(mapper.apply(getLeft())); } else { return (Either<T, R>) this; } }
/** Accepts both the left and right consumers, using the default values to set the empty side. */ public final void acceptBoth(Consumer<? super L> left, Consumer<? super R> right, @Nullable L defaultLeft, @Nullable R defaultRight) { left.accept(isLeft() ? getLeft() : defaultLeft); right.accept(isRight() ? getRight() : defaultRight); }
@SuppressWarnings("unchecked") public final <T> Either<L, T> mapRight(Function<? super R, ? extends T> mapper) { if (isLeft()) { return (Either<L, T>) this; } else { return Either.createRight(mapper.apply(getRight())); } }
@SuppressWarnings("unchecked") default <T> Either<L, T> mapRight(Function<? super R, ? extends T> mapper) { if (isLeft()) { return (Either<L, T>) this; } else { return Either.createRight(mapper.apply(getRight())); } }
/** Accepts both the left and right consumers, using the default values to set the empty side. */ public final void acceptBoth(Consumer<? super L> left, Consumer<? super R> right, L defaultLeft, R defaultRight) { left.accept(isLeft() ? getLeft() : defaultLeft); right.accept(isRight() ? getRight() : defaultRight); }
/** Accepts both the left and right consumers, using the default values to set the empty side. */ default void acceptBoth(Consumer<? super L> left, Consumer<? super R> right, L defaultLeft, R defaultRight) { left.accept(isLeft() ? getLeft() : defaultLeft); right.accept(isRight() ? getRight() : defaultRight); }