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


Java Stream.flatMap方法代码示例

本文整理汇总了Java中io.vavr.collection.Stream.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Stream.flatMap方法的具体用法?Java Stream.flatMap怎么用?Java Stream.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vavr.collection.Stream的用法示例。


在下文中一共展示了Stream.flatMap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forEach4

import io.vavr.collection.Stream; //导入方法依赖的package包/类
/**
 * Perform a For Comprehension over a Stream, accepting 3 generating functions.
 * This results in a four level nested internal iteration over the provided Publishers.
 *
 *  <pre>
 * {@code
 *
 *   import static cyclops.Streams.forEach4;
 *
forEach4(IntStream.range(1,10).boxed(),
a-> Stream.iterate(a,i->i+1).limit(10),
(a,b) -> Stream.<Integer>of(a+b),
(a,b,c) -> Stream.<Integer>just(a+b+c),
Tuple::tuple)
 *
 * }
 * </pre>
 *
 * @param value1 top level Stream
 * @param value2 Nested Stream
 * @param value3 Nested Stream
 * @param value4 Nested Stream
 * @param yieldingFunction  Generates a result per combination
 * @return Stream with an element per combination of nested publishers generated by the yielding function
 */
public static <T1, T2, T3, R1, R2, R3, R> Stream<R> forEach4(Stream<? extends T1> value1,
                                                           Function<? super T1, ? extends Stream<R1>> value2,
                                                           BiFunction<? super T1, ? super R1, ? extends Stream<R2>> value3,
                                                           Function3<? super T1, ? super R1, ? super R2, ? extends Stream<R3>> value4,
                                                           Function4<? super T1, ? super R1, ? super R2, ? super R3, ? extends R> yieldingFunction) {


    return value1.flatMap(in -> {

        Stream<R1> a = value2.apply(in);
        return a.flatMap(ina -> {
            Stream<R2> b = value3.apply(in,ina);
            return b.flatMap(inb -> {
                Stream<R3> c = value4.apply(in,ina,inb);
                return c.map(in2 -> yieldingFunction.apply(in, ina, inb, in2));
            });

        });

    });

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

示例2: forEach3

import io.vavr.collection.Stream; //导入方法依赖的package包/类
/**
 * Perform a For Comprehension over a Stream, accepting 2 generating function.
 * This results in a three level nested internal iteration over the provided Publishers.
 * <pre>
 * {@code
 *
 * import static Streams.forEach;
 *
 * forEach(IntStream.range(1,10).boxed(),
a-> Stream.iterate(a,i->i+1).limit(10),
(a,b) -> Stream.<Integer>of(a+b),
(a,b,c) ->a+b+c<10,
Tuple::tuple)
.toStreamX();
 * }
 * </pre>
 *
 * @param value1 top level Stream
 * @param value2 Nested publisher
 * @param value3 Nested publisher
 * @param filterFunction A filtering function, keeps values where the predicate holds
 * @param yieldingFunction Generates a result per combination
 * @return
 */
public static <T1, T2, R1, R2, R> Stream<R> forEach3(Stream<? extends T1> value1,
                                                     Function<? super T1, ? extends Stream<R1>> value2,
                                                     BiFunction<? super T1, ? super R1, ? extends Stream<R2>> value3,
                                                     Function3<? super T1, ? super R1, ? super R2, Boolean> filterFunction,
                                                     Function3<? super T1, ? super R1, ? super R2, ? extends R> yieldingFunction) {


    return value1.flatMap(in -> {

        Stream<R1> a = value2.apply(in);
        return a.flatMap(ina -> {
            Stream<R2> b = value3.apply(in,ina);
            return b.filter(in2->filterFunction.apply(in,ina,in2))
                    .map(in2 -> yieldingFunction.apply(in, ina, in2));
        });



    });
}
 
开发者ID:aol,项目名称:cyclops,代码行数:45,代码来源:Streams.java

示例3: forEach2

import io.vavr.collection.Stream; //导入方法依赖的package包/类
/**
 * Perform a For Comprehension over a Stream, accepting an additonal generating function.
 * This results in a two level nested internal iteration over the provided Publishers.
 *
 * <pre>
 * {@code
 *
 *  import static Streams.forEach2;
 *  forEach(IntStream.range(1, 10).boxed(),
 *          i -> Stream.range(i, 10), Tuple::tuple)
.forEach(System.out::println);

//(1, 1)
(1, 2)
(1, 3)
(1, 4)
...
 *
 * }</pre>
 *
 * @param value1 top level Stream
 * @param value2 Nested publisher
 * @param yieldingFunction Generates a result per combination
 * @return
 */
public static <T, R1, R> Stream<R> forEach2(Stream<? extends T> value1,
                                            Function<? super T, Stream<R1>> value2,
                                            BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) {


    return value1.flatMap(in -> {

        Stream<R1> a = value2.apply(in);
        return a.map(in2 -> yieldingFunction.apply(in,  in2));
    });

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


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