当前位置: 首页>>代码示例>>Java>>正文


Java Future.flatMap方法代码示例

本文整理汇总了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));
            });

        });

    });

}
 
开发者ID:aol,项目名称:cyclops,代码行数:47,代码来源:Futures.java

示例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));
        });


    });

}
 
开发者ID:aol,项目名称:cyclops,代码行数:41,代码来源:Futures.java

示例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));
    });




}
 
开发者ID:aol,项目名称:cyclops,代码行数:41,代码来源:Futures.java

示例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));
    });



}
 
开发者ID:aol,项目名称:cyclops,代码行数:34,代码来源:Futures.java


注:本文中的io.vavr.concurrent.Future.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。