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

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

本文整理了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

  1. /**
  2. * Yields a result for elements of the cross product of the underlying Trys.
  3. *
  4. * @param f a function that maps an element of the cross product to a result
  5. * @param <R> type of the resulting {@code Try} elements
  6. * @return an {@code Try} of mapped results
  7. */
  8. 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) {
  9. Objects.requireNonNull(f, "f is null");
  10. return
  11. ts1.flatMap(t1 ->
  12. ts2.flatMap(t2 ->
  13. ts3.flatMap(t3 ->
  14. ts4.flatMap(t4 ->
  15. ts5.flatMap(t5 ->
  16. ts6.flatMap(t6 ->
  17. ts7.flatMap(t7 ->
  18. ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8)))))))));
  19. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Returns a this and that Future result combined using a given combinator function.
  3. * <p>
  4. * If this Future failed the result contains this failure. Otherwise the result contains that failure or
  5. * a combination of both successful Future results.
  6. *
  7. * @param that Another Future
  8. * @param combinator The combinator function
  9. * @param <U> Result type of {@code that}
  10. * @param <R> Result type of {@code f}
  11. * @return A new Future that returns both Future results.
  12. * @throws NullPointerException if {@code that} is null
  13. */
  14. @SuppressWarnings({"deprecation", "unchecked"})
  15. default <U, R> Future<R> zipWith(Future<? extends U> that, BiFunction<? super T, ? super U, ? extends R> combinator) {
  16. Objects.requireNonNull(that, "that is null");
  17. Objects.requireNonNull(combinator, "combinator is null");
  18. return run(executor(), complete ->
  19. onComplete(res1 -> {
  20. if (res1.isFailure()) {
  21. complete.with((Try.Failure<R>) res1);
  22. } else {
  23. that.onComplete(res2 -> {
  24. final Try<R> result = res1.flatMap(t -> res2.map(u -> combinator.apply(t, u)));
  25. complete.with(result);
  26. });
  27. }
  28. })
  29. );
  30. }

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

  1. /**
  2. * Yields a result for elements of the cross product of the underlying Trys.
  3. *
  4. * @param f a function that maps an element of the cross product to a result
  5. * @param <R> type of the resulting {@code Try} elements
  6. * @return an {@code Try} of mapped results
  7. */
  8. 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) {
  9. Objects.requireNonNull(f, "f is null");
  10. return
  11. ts1.flatMap(t1 ->
  12. ts2.flatMap(t2 ->
  13. ts3.flatMap(t3 ->
  14. ts4.flatMap(t4 ->
  15. ts5.flatMap(t5 ->
  16. ts6.flatMap(t6 ->
  17. ts7.flatMap(t7 ->
  18. ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8)))))))));
  19. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * 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.
  3. *
  4. * @param <U> type of a value contained by successful {@link Try} created by {@code mapper} function
  5. * @param mapper the {@link Function} to use in the {@link Try#flatMap(Function) flatMap} operation.
  6. *
  7. * @return a new {@link org.assertj.vavr.api.AbstractTryAssert} for assertions chaining on the flatMap of the Try.
  8. * @throws AssertionError if the actual {@link Try} is null.
  9. */
  10. @CheckReturnValue
  11. public <U> AbstractTryAssert<?, U> flatMap(Function<? super VALUE, Try<U>> mapper) {
  12. isNotNull();
  13. return VavrAssertions.assertThat(actual.flatMap(mapper));
  14. }

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

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

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

  1. /**
  2. * Returns the row / column value from the specified table.
  3. *
  4. * @param dataRow The DataRow to get the table and column from.
  5. * @return Returns the data if found, as a Try.
  6. */
  7. Try<Object> getCellData(DataRow dataRow) {
  8. return getColumn
  9. .apply(dataRow.table().columns())
  10. .flatMap(col -> Try.success(col.valueAt(dataRow.rowIdx())));
  11. }
  12. }

相关文章