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


Java Stream.of方法代码示例

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


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

示例1: tailRec

import io.vavr.collection.Stream; //导入方法依赖的package包/类
public static  <T,R> Stream<R> tailRec(T initial, Function<? super T, ? extends Stream<? extends io.vavr.control.Either<T, R>>> fn) {
    Stream<io.vavr.control.Either<T, R>> next = Stream.of(io.vavr.control.Either.left(initial));

    boolean newValue[] = {true};
    for(;;){

        Stream<io.vavr.control.Either<T, R>> rebuild = Stream.of();
        for(io.vavr.control.Either<T,R> e : next){
            Stream<? extends io.vavr.control.Either<T, R>> r = e.fold(s -> {
                        newValue[0] = true;

                        return fn.apply(s);
                    },
                    p -> {
                        newValue[0] = false;
                        return Stream.of(e);
                    });
            rebuild = Stream.concat(rebuild,r);
        }
        next = rebuild;
        if(!newValue[0])
            break;

    }

    return next.filter(io.vavr.control.Either::isRight).map(io.vavr.control.Either::get);
}
 
开发者ID:aol,项目名称:cyclops,代码行数:28,代码来源:Streams.java

示例2: tailRecEither

import io.vavr.collection.Stream; //导入方法依赖的package包/类
public static  <T,R> Stream<R> tailRecEither(T initial, Function<? super T, ? extends Stream<? extends Either<T, R>>> fn) {
    Stream<Either<T, R>> next = Stream.of(Either.left(initial));

    boolean newValue[] = {true};
    for(;;){

        Stream<Either<T, R>> rebuild = Stream.of();
        for(Either<T,R> e : next){
            Stream<? extends Either<T, R>> r = e.visit(s -> {
                        newValue[0] = true;

                        return fn.apply(s);
                    },
                    p -> {
                        newValue[0] = false;
                        return Stream.of(e);
                    });
            rebuild = Stream.concat(rebuild,r);
        }

        next = rebuild;
        if(!newValue[0])
            break;

    }

    return next.filter(Either::isRight).map(e->e.orElse(null));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:29,代码来源:Streams.java

示例3: testStream

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStream() throws Exception {
    Stream<A> src = Stream.of(new B("a", "b"));
    String json = MAPPER.writeValueAsString(new StreamPojo().setValue(src));
    Assert.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}");
    StreamPojo pojo = MAPPER.readValue(json, StreamPojo.class);
    Stream<A> restored = pojo.getValue();
    Assert.assertTrue(restored.get(0) instanceof B);
    Assert.assertEquals(restored.get(0).a, "a");
    Assert.assertEquals(((B) restored.get(0)).b, "b");
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:ExtFieldsPojoTest.java

示例4: testStreamOfString

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStreamOfString() throws Exception {
    String src0 = "A";
    String src1 = "B";
    String src2 = "C";
    Stream<String> src = Stream.of(src0, src1, src2);
    String json = MAPPER.writeValueAsString(new ParameterizedStreamPojo<>(src));
    Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
    ParameterizedStreamPojo<java.lang.String> restored = 
            MAPPER.readValue(json, new TypeReference<ParameterizedStreamPojo<java.lang.String>>(){});
    Assert.assertEquals(src, restored.getValue());
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:13,代码来源:ParameterizedPojoTest.java

示例5: testStreamOfTuple

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStreamOfTuple() throws Exception {
    String src00 = "A";
    String src01 = "B";
    Tuple2<String, String> src0 = Tuple.of(src00, src01);
    Stream<Tuple2<String, String>> src = Stream.of(src0);
    String json = MAPPER.writeValueAsString(new ParameterizedStreamPojo<>(src));
    Assert.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
    ParameterizedStreamPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = 
            MAPPER.readValue(json, new TypeReference<ParameterizedStreamPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assert.assertEquals(src, restored.getValue());
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:13,代码来源:ParameterizedPojoTest.java

示例6: testStreamOfString

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStreamOfString() throws Exception {
    String src0 = "A";
    String src1 = "B";
    String src2 = "C";
    Stream<String> src = Stream.of(src0, src1, src2);
    String json = MAPPER.writeValueAsString(new StreamOfString().setValue(src));
    Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
    StreamOfString restored = MAPPER.readValue(json, StreamOfString.class);
    Assert.assertEquals(src, restored.getValue());
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:SimplePojoTest.java

示例7: testStreamOfTuple

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStreamOfTuple() throws Exception {
    String src00 = "A";
    String src01 = "B";
    Tuple2<String, String> src0 = Tuple.of(src00, src01);
    Stream<Tuple2<String, String>> src = Stream.of(src0);
    String json = MAPPER.writeValueAsString(new StreamOfTuple().setValue(src));
    Assert.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
    StreamOfTuple restored = MAPPER.readValue(json, StreamOfTuple.class);
    Assert.assertEquals(src, restored.getValue());
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:SimplePojoTest.java

示例8: testStream

import io.vavr.collection.Stream; //导入方法依赖的package包/类
@Test
public void testStream() throws Exception {
    Stream<I> src = Stream.of(new A(), new B());
    String json = MAPPER.writeValueAsString(new StreamPojo().setValue(src));
    Assert.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"}]}");
    StreamPojo pojo = MAPPER.readValue(json, StreamPojo.class);
    Stream<I> restored = pojo.getValue();
    Assert.assertTrue(restored.get(0) instanceof A);
    Assert.assertTrue(restored.get(1) instanceof B);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:11,代码来源:PolymorphicPojoTest.java


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