本文整理汇总了Java中io.vavr.concurrent.Future.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Future.flatMap方法的具体用法?Java Future.flatMap怎么用?Java Future.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vavr.concurrent.Future
的用法示例。
在下文中一共展示了Future.flatMap方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forEach4
import io.vavr.concurrent.Future; //导入方法依赖的package包/类
/**
* Perform a For Comprehension over a Future, accepting 3 generating function.
* This results in a four level nested internal iteration over the provided Futures.
*
* <pre>
* {@code
*
* import static com.oath.cyclops.reactor.Futures.forEach4;
*
forEach4(Future.just(1),
a-> Future.just(a+1),
(a,b) -> Future.<Integer>just(a+b),
a (a,b,c) -> Future.<Integer>just(a+b+c),
Tuple::tuple)
*
* }
* </pre>
*
* @param value1 top level Future
* @param value2 Nested Future
* @param value3 Nested Future
* @param value4 Nested Future
* @param yieldingFunction Generates a result per combination
* @return Future with a combined value generated by the yielding function
*/
public static <T1, T2, T3, R1, R2, R3, R> Future<R> forEach4(Future<? extends T1> value1,
Function<? super T1, ? extends Future<R1>> value2,
BiFunction<? super T1, ? super R1, ? extends Future<R2>> value3,
Function3<? super T1, ? super R1, ? super R2, ? extends Future<R3>> value4,
Function4<? super T1, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) {
return value1.flatMap(in -> {
Future<R1> a = value2.apply(in);
return a.flatMap(ina -> {
Future<R2> b = value3.apply(in,ina);
return b.flatMap(inb -> {
Future<R3> c = value4.apply(in,ina,inb);
return c.map(in2 -> yieldingFunction.apply(in, ina, inb, in2));
});
});
});
}
示例2: forEach3
import io.vavr.concurrent.Future; //导入方法依赖的package包/类
/**
* Perform a For Comprehension over a Future, accepting 2 generating function.
* This results in a three level nested internal iteration over the provided Futures.
*
* <pre>
* {@code
*
* import static com.oath.cyclops.reactor.Futures.forEach3;
*
forEach3(Future.just(1),
a-> Future.just(a+1),
(a,b) -> Future.<Integer>just(a+b),
Tuple::tuple)
*
* }
* </pre>
*
* @param value1 top level Future
* @param value2 Nested Future
* @param value3 Nested Future
* @param yieldingFunction Generates a result per combination
* @return Future with a combined value generated by the yielding function
*/
public static <T1, T2, R1, R2, R> Future<R> forEach3(Future<? extends T1> value1,
Function<? super T1, ? extends Future<R1>> value2,
BiFunction<? super T1, ? super R1, ? extends Future<R2>> value3,
Function3<? super T1, ? super R1, ? super R2, ? extends R> yieldingFunction) {
return value1.flatMap(in -> {
Future<R1> a = value2.apply(in);
return a.flatMap(ina -> {
Future<R2> b = value3.apply(in,ina);
return b.map(in2 -> yieldingFunction.apply(in, ina, in2));
});
});
}
示例3: forEach2
import io.vavr.concurrent.Future; //导入方法依赖的package包/类
/**
*
* Perform a For Comprehension over a Future, accepting a generating function.
* This results in a two level nested internal iteration over the provided Futures.
*
* <pre>
* {@code
*
* import static com.oath.cyclops.reactor.Futures.forEach;
*
* forEach(Future.just(1),
a-> Future.just(a+1),
(a,b) -> Future.<Integer>just(a+b),
(a,b,c) -> a+b+c <100,
Tuple::tuple);
*
* }
* </pre>
*
* @param value1 top level Future
* @param value2 Nested Future
* @param filterFunction A filtering function, keeps values where the predicate holds
* @param yieldingFunction Generates a result per combination
* @return Future with a combined value generated by the yielding function
*/
public static <T, R1, R> Future<R> forEach2(Future<? extends T> value1, Function<? super T, ? extends Future<R1>> value2,
BiFunction<? super T, ? super R1, Boolean> filterFunction,
BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) {
return value1.flatMap(in -> {
Future<R1> a = value2.apply(in);
return a.filter(in2->filterFunction.apply(in,in2))
.map(in2 -> yieldingFunction.apply(in, in2));
});
}
示例4: forEach
import io.vavr.concurrent.Future; //导入方法依赖的package包/类
/**
* Perform a For Comprehension over a Future, accepting a generating function.
* This results in a two level nested internal iteration over the provided Futures.
*
* <pre>
* {@code
*
* import static com.oath.cyclops.reactor.Futures.forEach;
*
forEach(Future.just(1),
a-> Future.just(a+1),
Tuple::tuple)
*
* }
* </pre>
*
* @param value1 top level Future
* @param value2 Nested Future
* @param yieldingFunction Generates a result per combination
* @return Future with a combined value generated by the yielding function
*/
public static <T, R1, R> Future<R> forEach2(Future<? extends T> value1, Function<? super T, Future<R1>> value2,
BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) {
return value1.flatMap(in -> {
Future<R1> a = value2.apply(in);
return a.map(in2 -> yieldingFunction.apply(in, in2));
});
}