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

x33g5p2x  于2022-01-30 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(109)

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

Try.sequence介绍

[英]Reduces many Trys into a single Try by transforming an Iterable> into a Try>. If any of the Trys are Try.Failure, then this returns a Try.Failure.
[中]通过将Iterable>转换为Try>,将多次尝试减少为一次尝试。如果任何一次尝试都失败了。失败,则返回一次尝试。失败

代码示例

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

/**
 * Maps the values of an iterable to a sequence of mapped values into a single {@code Try} by
 * transforming an {@code Iterable<? extends T>} into a {@code Try<Seq<U>>}.
 * <p>
 *
 * @param values   An {@code Iterable} of values.
 * @param mapper   A mapper of values to Trys
 * @param <T>      The type of the given values.
 * @param <U>      The mapped value type.
 * @return A {@code Try} of a {@link Seq} of results.
 * @throws NullPointerException if values or f is null.
 */
static <T, U> Try<Seq<U>> traverse(Iterable<? extends T> values, Function<? super T, ? extends Try<? extends U>> mapper) {
  Objects.requireNonNull(values, "values is null");
  Objects.requireNonNull(mapper, "mapper is null");
  return sequence(Iterator.ofAll(values).map(mapper));
}

代码示例来源:origin: martincooper/java-datatable

/**
 * Converts a Seq<Try<IDataColumn>> into a Try<Seq<IDataColumn>>
 *
 * @param items The values to convert.
 * @return Returns the converted items.
 */
private Try<Seq<IDataColumn>> toSequence(Seq<Try<IDataColumn>> items) {
  return Try.sequence(items);
}

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

/**
 * Maps the values of an iterable to a sequence of mapped values into a single {@code Try} by
 * transforming an {@code Iterable<? extends T>} into a {@code Try<Seq<U>>}.
 * <p>
 *
 * @param values   An {@code Iterable} of values.
 * @param mapper   A mapper of values to Trys
 * @param <T>      The type of the given values.
 * @param <U>      The mapped value type.
 * @return A {@code Try} of a {@link Seq} of results.
 * @throws NullPointerException if values or f is null.
 */
static <T, U> Try<Seq<U>> traverse(Iterable<? extends T> values, Function<? super T, ? extends Try<? extends U>> mapper) {
  Objects.requireNonNull(values, "values is null");
  Objects.requireNonNull(mapper, "mapper is null");
  return sequence(Iterator.ofAll(values).map(mapper));
}

相关文章