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

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

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

Try.flatMap介绍

[英]Shortcut for flatMapTry(mapper::apply), see #flatMapTry(CheckedFunction1).
[中]flatMapTry的快捷方式(mapper::apply),请参见#flatMapTry(CheckedFunction1)。

代码示例

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.flatMap(t5 ->
    ts6.flatMap(t6 ->
    ts7.flatMap(t7 ->
    ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8)))))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.flatMap(t5 ->
    ts6.flatMap(t6 ->
    ts7.map(t7 -> f.apply(t1, t2, t3, t4, t5, t6, t7))))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.map(t5 -> f.apply(t1, t2, t3, t4, t5))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.flatMap(t5 ->
    ts6.map(t6 -> f.apply(t1, t2, t3, t4, t5, t6)))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.map(t4 -> f.apply(t1, t2, t3, t4)))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(BiFunction<? super T1, ? super T2, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.map(t2 -> f.apply(t1, t2)));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function3<? super T1, ? super T2, ? super T3, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.map(t3 -> f.apply(t1, t2, t3))));
}

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

/**
 * Returns a this and that Future result combined using a given combinator function.
 * <p>
 * If this Future failed the result contains this failure. Otherwise the result contains that failure or
 * a combination of both successful Future results.
 *
 * @param that       Another Future
 * @param combinator The combinator function
 * @param <U>        Result type of {@code that}
 * @param <R>        Result type of {@code f}
 * @return A new Future that returns both Future results.
 * @throws NullPointerException if {@code that} is null
 */
@SuppressWarnings({"deprecation", "unchecked"})
default <U, R> Future<R> zipWith(Future<? extends U> that, BiFunction<? super T, ? super U, ? extends R> combinator) {
  Objects.requireNonNull(that, "that is null");
  Objects.requireNonNull(combinator, "combinator is null");
  return run(executor(), complete ->
    onComplete(res1 -> {
      if (res1.isFailure()) {
        complete.with((Try.Failure<R>) res1);
      } else {
        that.onComplete(res2 -> {
          final Try<R> result = res1.flatMap(t -> res2.map(u -> combinator.apply(t, u)));
          complete.with(result);
        });
      }
    })
  );
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.flatMap(t5 ->
    ts6.flatMap(t6 ->
    ts7.flatMap(t7 ->
    ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8)))))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.flatMap(t5 ->
    ts6.map(t6 -> f.apply(t1, t2, t3, t4, t5, t6)))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.flatMap(t4 ->
    ts5.map(t5 -> f.apply(t1, t2, t3, t4, t5))))));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.flatMap(t3 ->
    ts4.map(t4 -> f.apply(t1, t2, t3, t4)))));
}

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

/**
 * Validate the sort items and columns are ok to perform a sort.
 *
 * @param table The underlying data table.
 * @param sortItems The sort items.
 * @return Return the validation result.
 */
private static Try<Void> validateSortColumns(DataTable table, Seq<SortItem> sortItems) {
  return validateSortColumnIdentity(table, sortItems)
      .flatMap(DataSort::validateColumnsAreComparable);
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(BiFunction<? super T1, ? super T2, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.map(t2 -> f.apply(t1, t2)));
}

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

/**
* Yields a result for elements of the cross product of the underlying Trys.
*
* @param f a function that maps an element of the cross product to a result
* @param <R> type of the resulting {@code Try} elements
* @return an {@code Try} of mapped results
*/
public <R> Try<R> yield(Function3<? super T1, ? super T2, ? super T3, ? extends R> f) {
  Objects.requireNonNull(f, "f is null");
  return
    ts1.flatMap(t1 ->
    ts2.flatMap(t2 ->
    ts3.map(t3 -> f.apply(t1, t2, t3))));
}

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

static <T extends DataRowCollectionBase> Try<T> buildRowCollection(DataTable table, Iterable<DataRow> rows, BiFunction<DataTable, Iterable<DataRow>, T> builder) {
  return validateDataRows(table, rows)
      .flatMap(x -> Try.success(builder.apply(table, rows)));
}

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

/**
 * Validates the column data.
 *
 * @param columns The columns to validate.
 * @return Returns a Success or Failure.
 */
private static Try<Seq<IDataColumn>> validateColumns(Iterable<IDataColumn> columns) {
  return validateColumnNames(Stream.ofAll(columns))
      .flatMap(DataTable::validateColumnDataLength);
}

代码示例来源:origin: org.assertj/assertj-vavr

/**
 * Call {@link Try#flatMap(Function) flatMap} on the {@code Try} under test, assertions chained afterwards are performed on the {@code Try} resulting from the flatMap call.
 *
 * @param <U> type of a value contained by successful {@link Try} created by {@code mapper} function
 * @param mapper the {@link Function} to use in the {@link Try#flatMap(Function) flatMap} operation.
 *
 * @return a new {@link org.assertj.vavr.api.AbstractTryAssert} for assertions chaining on the flatMap of the Try.
 * @throws AssertionError if the actual {@link Try} is null.
 */
@CheckReturnValue
public <U> AbstractTryAssert<?, U> flatMap(Function<? super VALUE, Try<U>> mapper) {
  isNotNull();
  return VavrAssertions.assertThat(actual.flatMap(mapper));
}

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

private Try<DataTable> checkColumnsAndBuild(String changeType, Supplier<Try<Vector<IDataColumn>>> columns) {
  // Calculate the new column collection then try and build a DataTable from it.
  Try<DataTable> result = columns.get()
      .flatMap(cols -> DataTable.build(this.table.name(), cols));
  return result.isSuccess()
      ? result
      : error("Error " + changeType + " column at specified index.", result.getCause());
}

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

/**
   * Returns the row / column value from the specified table.
   *
   * @param dataRow The DataRow to get the table and column from.
   * @return Returns the data if found, as a Try.
   */
  Try<Object> getCellData(DataRow dataRow) {
    return getColumn
        .apply(dataRow.table().columns())
        .flatMap(col -> Try.success(col.valueAt(dataRow.rowIdx())));
  }
}

相关文章