io.vavr.control.Either.right()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中io.vavr.control.Either.right()方法的一些代码示例,展示了Either.right()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Either.right()方法的具体详情如下:
包路径:io.vavr.control.Either
类名称:Either
方法名:right

Either.right介绍

[英]Returns a RightProjection of this Either.
[中]返回此项的右投影。

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link Either#right(Object)}
 *
 * @param <L>   Type of left value.
 * @param <R>   Type of right value.
 * @param right The value.
 * @return A new {@link Either.Right} instance.
 */
@SuppressWarnings("unchecked")
public static <L, R> Either.Right<L, R> Right(R right) {
  return (Either.Right<L, R>) Either.right(right);
}

代码示例来源:origin: vavr-io/vavr

public <L2, R2> RightProjection<L2, R2> bimap(Function<? super L, ? extends L2> leftMapper, Function<? super R, ? extends R2> rightMapper) {
  return either.<L2, R2> bimap(leftMapper, rightMapper).right();
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Either}.
 *
 * @param <R>   right type
 * @param right A supplier of a right value
 * @return A new {@link Either.Right} containing the result of {@code right} if this is empty, otherwise
 * a new {@link Either.Left} containing this value.
 * @throws NullPointerException if {@code right} is null
 * @deprecated Use {@link #toEither(Supplier)} instead.
 */
@Deprecated
default <R> Either<T, R> toLeft(Supplier<? extends R> right) {
  Objects.requireNonNull(right, "right is null");
  return isEmpty() ? Either.right(right.get()) : Either.left(get());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Maps the right value if the projected Either is a Right.
 *
 * @param mapper A mapper which takes a right value and returns a value of type U
 * @param <U>    The new type of a Right value
 * @return A new RightProjection
 */
@SuppressWarnings("unchecked")
@Override
public <U> RightProjection<L, U> map(Function<? super R, ? extends U> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  if (either.isRight()) {
    return either.map((Function<R, U>) mapper).right();
  } else {
    return (RightProjection<L, U>) this;
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Either}.
 *
 * @param <L>  left type
 * @param left A supplier of a left value
 * @return A new {@link Either.Left} containing the result of {@code left} if this is empty, otherwise
 * a new {@link Either.Right} containing this value.
 * @throws NullPointerException if {@code left} is null
 * @deprecated Use {@link #toEither(Supplier)} instead.
 */
@Deprecated
default <L> Either<L, T> toRight(Supplier<? extends L> left) {
  Objects.requireNonNull(left, "left is null");
  return isEmpty() ? Either.left(left.get()) : Either.right(get());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Either}.
 *
 * @param <R>   right type
 * @param right An instance of a right value
 * @return A new {@link Either.Right} containing the value of {@code right} if this is empty, otherwise
 * a new {@link Either.Left} containing this value.
 * @deprecated Use {@link #toEither(Object)} instead.
 */
@Deprecated
default <R> Either<T, R> toLeft(R right) {
  return isEmpty() ? Either.right(right) : Either.left(get());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this to a {@link Either}.
 *
 * @param <L>  left type
 * @param left An instance of a left value
 * @return A new {@link Either.Left} containing the value of {@code left} if this is empty, otherwise
 * a new {@link Either.Right} containing this value.
 * @deprecated Use {@link #toEither(Object)} instead.
 */
@Deprecated
default <L> Either<L, T> toRight(L left) {
  return isEmpty() ? Either.left(left) : Either.right(get());
}

代码示例来源:origin: vavr-io/vavr

/**
 * Maps the value of this Either if it is a Right, performs no operation if this is a Left.
 *
 * <pre><code>
 * import static io.vavr.API.*;
 *
 * // = Right("A")
 * Right("a").map(String::toUpperCase);
 *
 * // = Left(1)
 * Left(1).map(String::toUpperCase);
 * </code></pre>
 *
 * @param mapper 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")
@Override
default <U> Either<L, U> map(Function<? super R, ? extends U> mapper) {
  Objects.requireNonNull(mapper, "mapper is null");
  if (isRight()) {
    return Either.right(mapper.apply(get()));
  } else {
    return (Either<L, U>) this;
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this {@code Try} to an {@link Either}.
 *
 * @return A new {@code Either}
 */
default Either<Throwable, T> toEither() {
  if (isFailure()) {
    return Either.left(getCause());
  } else {
    return Either.right(get());
  }
}

代码示例来源:origin: vavr-io/vavr

/**
 * Converts this Validation to an {@link Either}.
 *
 * @return {@code Either.right(get())} if this is valid, otherwise {@code Either.left(getError())}.
 */
default Either<E, T> toEither() {
  return isValid() ? Either.right(get()) : Either.left(getError());
}

代码示例来源:origin: vavr-io/vavr

return Either.right(rightValues);

代码示例来源:origin: jdbi/jdbi

@Test
public void testGetRightEitherArgumentInferredShouldNotBeEmpty() {
  Optional<Argument> arg = unit.build(new GenericType<Either<?, ?>>() {}.getType(),
      Either.right(1), null);
  assertThat(arg).isNotEmpty();
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testGetRightEitherArgumentShouldNotBeEmpty() {
  Optional<Argument> arg = unit.build(new GenericType<Either<String, Integer>>() {}.getType(),
      Either.right(1), null);
  assertThat(arg).isNotEmpty();
}

代码示例来源:origin: jdbi/jdbi

@Test
public void testGetEitherRightShouldReturnCorrectRow() {
  Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME)
      .bind("name", Either.right("brian"))
      .mapToBean(Something.class)
      .findOnly();
  assertThat(result).isEqualTo(BRIANSOMETHING);
}

代码示例来源:origin: vavr-io/vavr

.apply((leftPartition, rightPartition) -> leftPartition.hasNext()
  ? Either.left(leftPartition.map(Either::getLeft).toVector())
  : Either.right(rightPartition.map(Either::get).toVector())
);

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link Either#right(Object)}
 *
 * @param <L>   Type of left value.
 * @param <R>   Type of right value.
 * @param right The value.
 * @return A new {@link Either.Right} instance.
 */
@SuppressWarnings("unchecked")
public static <L, R> Either.Right<L, R> Right(R right) {
  return (Either.Right<L, R>) Either.right(right);
}

代码示例来源:origin: com.github.robozonky/robozonky-common

@Override
  public synchronized Either<Throwable, T> get() {
    if (!needsReload()) {
      logger.trace("Not reloading {}.", this);
      return Either.right(value.get());
    }
    logger.trace("Reloading {}.", this);
    return Try.ofSupplier(getOperation())
        .peek(v -> processRetrievedValue(v, value::set))
        .toEither();
  }
}

代码示例来源:origin: io.vavr/vavr

/**
 * Converts this {@code Try} to an {@link Either}.
 *
 * @return A new {@code Either}
 */
default Either<Throwable, T> toEither() {
  if (isFailure()) {
    return Either.left(getCause());
  } else {
    return Either.right(get());
  }
}

代码示例来源:origin: io.vavr/vavr

/**
 * Converts this Validation to an {@link Either}.
 *
 * @return {@code Either.right(get())} if this is valid, otherwise {@code Either.left(getError())}.
 */
default Either<E, T> toEither() {
  return isValid() ? Either.right(get()) : Either.left(getError());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testRightEitherOfString() throws Exception {
  String srcr = "A";
  Either<Object, String> src = Either.right(srcr);
  String json = MAPPER.writeValueAsString(new ParameterizedEitherPojo<>(src));
  Assert.assertEquals(json, "{\"value\":[\"right\",\"A\"]}");
  ParameterizedEitherPojo<java.lang.Object, java.lang.String> restored = 
      MAPPER.readValue(json, new TypeReference<ParameterizedEitherPojo<java.lang.Object, java.lang.String>>(){});
  Assert.assertEquals(src, restored.getValue());
}

相关文章