• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Lazy类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中io.vavr.Lazy的典型用法代码示例。如果您正苦于以下问题:Java Lazy类的具体用法?Java Lazy怎么用?Java Lazy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

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

示例1: deserialize

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Override
public Lazy<?> deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException {
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        Type subType = parameterizedType.getActualTypeArguments()[0];
        return Lazy.of(() -> ctx.deserialize(json, subType));
    } else {
        return Lazy.of(() -> json);
    }
}
 

开发者ID:vavr-io,
项目名称:vavr-gson,
代码行数:11,
代码来源:LazyConverter.java

示例2: testLazyOfString

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testLazyOfString() throws Exception {
    String src0 = "A";
    Lazy<String> src = Lazy.of(() -> src0);
    String json = MAPPER.writeValueAsString(new ParameterizedLazyPojo<>(src));
    Assert.assertEquals(json, "{\"value\":\"A\"}");
    ParameterizedLazyPojo<java.lang.String> restored = 
            MAPPER.readValue(json, new TypeReference<ParameterizedLazyPojo<java.lang.String>>(){});
    Assert.assertEquals(src, restored.getValue());
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:11,
代码来源:ParameterizedPojoTest.java

示例3: tailRec

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public static <L, T, R> Lazy<R> tailRec(T initial, Function<? super T, ? extends Lazy<? extends io.vavr.control.Either<T, R>>> fn) {
    Lazy<? extends io.vavr.control.Either<T, R>> next[] = new Lazy[1];
    next[0] = Lazy.of(()->io.vavr.control.Either.left(initial));
    boolean cont = true;
    do {
        cont = next[0].map(p -> p.fold(s -> {
            next[0] = fn.apply(s);
            return true;
        }, pr -> false)).getOrElse(false);
    } while (cont);
    return next[0].map(io.vavr.control.Either::get);
}
 

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

示例4: tailRecEither

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public static <T, R> Lazy< R> tailRecEither(T initial, Function<? super T, ? extends Lazy<? extends cyclops.control.Either<T, R>>> fn) {
    Lazy<? extends cyclops.control.Either<T, R>> next[] = new Lazy[1];
    next[0] = Lazy.of(()-> cyclops.control.Either.left(initial));
    boolean cont = true;
    do {
        cont = next[0].map(p -> p.visit(s -> {
            next[0] = fn.apply(s);
            return true;
        }, pr -> false)).getOrElse(false);
    } while (cont);
    return next[0].map(e->e.orElse(null));
}
 

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

示例5: testLazyOfString

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testLazyOfString() throws Exception {
    String src0 = "A";
    Lazy<String> src = Lazy.of(() -> src0);
    String json = MAPPER.writeValueAsString(new LazyOfString().setValue(src));
    Assert.assertEquals(json, "{\"value\":\"A\"}");
    LazyOfString restored = MAPPER.readValue(json, LazyOfString.class);
    Assert.assertEquals(src, restored.getValue());
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:10,
代码来源:SimplePojoTest.java

示例6: testLazyOfTuple

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testLazyOfTuple() throws Exception {
    String src00 = "A";
    String src01 = "B";
    Tuple2<String, String> src0 = Tuple.of(src00, src01);
    Lazy<Tuple2<String, String>> src = Lazy.of(() -> src0);
    String json = MAPPER.writeValueAsString(new ParameterizedLazyPojo<>(src));
    Assert.assertEquals(json, "{\"value\":[\"A\",\"B\"]}");
    ParameterizedLazyPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = 
            MAPPER.readValue(json, new TypeReference<ParameterizedLazyPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assert.assertEquals(src, restored.getValue());
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:13,
代码来源:ParameterizedPojoTest.java

示例7: unit

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void unit(){

    LazyKind<String> opt = Instances.unit()
                                        .unit("hello")
                                        .convert(LazyKind::narrowK);

    assertThat(opt,equalTo(Lazy.of(()->"hello")));
}
 

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

示例8: functor

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void functor(){
    Higher<lazy,Integer> res =null;
    LazyKind<Integer> x = LazyKind.narrowK(res);
    LazyKind<Integer> opt = Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Instances.functor().map((String v) ->v.length(), h))
                                 .convert(r-> LazyKind.narrowK(r));

    assertThat(opt,equalTo(Lazy.of(()->"hello".length())));
}
 

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

示例9: applicative

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void applicative(){

    LazyKind<Function1<Integer,Integer>> optFn = Instances.unit()
                                                              .unit(l1((Integer i) ->i*2))
                                                              .convert(LazyKind::narrowK);

    LazyKind<Integer> opt = Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Instances.functor().map((String v) ->v.length(), h))
                                 .applyHKT(h-> Instances.applicative().ap(optFn, h))
                                 .convert(LazyKind::narrowK);

    assertThat(opt,equalTo(Lazy.of(()->"hello".length()*2)));
}
 

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

示例10: monad

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void monad(){

    LazyKind<Integer> opt = Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Instances.monad().flatMap((String v) -> Instances.unit().unit(v.length()), h))
                                 .convert(LazyKind::narrowK);

    assertThat(opt,equalTo(Lazy.of(()->"hello".length())));
}
 

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

示例11: monadZeroFilter

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void monadZeroFilter(){

    LazyKind<String> opt = Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Instances.monadZero().filter((String t)->t.startsWith("he"), h))
                                 .convert(LazyKind::narrowK);

    assertThat(opt,equalTo(Lazy.of(()->"hello")));
}
 

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

示例12: monadZeroFilterOut

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void monadZeroFilterOut(){

    LazyKind<String> opt = Instances.unit()
                                 .unit("hello")
                                 .applyHKT(h-> Instances.monadZero().filter((String t)->!t.startsWith("he"), h))
                                 .convert(LazyKind::narrowK);

    assertThat(opt,equalTo(Lazy.of(()->null)));
}
 

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

示例13: testLazy

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testLazy() throws Exception {
    Lazy<I> src = Lazy.of(A::new);
    String json = MAPPER.writeValueAsString(new LazyPojo().setValue(src));
    Assert.assertEquals(json, "{\"value\":{\"type\":\"a\"}}");
    LazyPojo pojo = MAPPER.readValue(json, LazyPojo.class);
    Lazy<I> restored = pojo.getValue();
    Assert.assertTrue(restored.get() instanceof A);
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:10,
代码来源:PolymorphicPojoTest.java

示例14: monadPlusNonEmpty

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void monadPlusNonEmpty(){

    Monoid<LazyKind<Integer>> m = Monoid.of(LazyKind.widen(Lazy.of(()->null)), (a, b)->a.get()==null ? b : a);
    LazyKind<Integer> opt = Instances.<Integer>monadPlusK(m)
                                  .plus(LazyKind.widen(Lazy.of(()->5)), LazyKind.widen(Lazy.of(()->10)))
                                  .convert(LazyKind::narrowK);
    assertThat(opt,equalTo(Lazy.of(()->5)));
}
 

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

示例15: foldLeft

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void  foldLeft(){
    int sum  = Instances.foldable()
                    .foldLeft(0, (a,b)->a+b, LazyKind.widen(Lazy.of(()->4)));

    assertThat(sum,equalTo(4));
}
 

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

示例16: foldRight

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void  foldRight(){
    int sum  = Instances.foldable()
                    .foldRight(0, (a,b)->a+b, LazyKind.widen(Lazy.of(()->1)));

    assertThat(sum,equalTo(1));
}
 

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

示例17: traverse

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void traverse(){
   Maybe<Higher<lazy, Integer>> res = Instances.traverse()
                                                               .traverseA(Maybe.Instances.applicative(), (Integer a)->Maybe.just(a*2), LazyKind.of(()->1))
                                                             .convert(Maybe::narrowK);


   assertThat(res,equalTo(Maybe.just(Lazy.of(()->2))));
}
 

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

示例18: modifyType

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Override
public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, TypeFactory typeFactory)
{
    final Class<?> raw = type.getRawClass();
    if (Seq.class.isAssignableFrom(raw) && CharSeq.class != raw) {
        return CollectionLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    }
    if (Set.class.isAssignableFrom(raw)) {
        return CollectionLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return CollectionLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    }
    if (Map.class.isAssignableFrom(raw)) {
        return MapLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0), type.containedTypeOrUnknown(1));
    }
    if (Multimap.class.isAssignableFrom(raw)) {
        return MapLikeType.upgradeFrom(type, type.containedTypeOrUnknown(0), type.containedTypeOrUnknown(1));
    }
    if (Lazy.class.isAssignableFrom(raw)) {
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    }
    if (Option.class.isAssignableFrom(raw)) {
        return ReferenceType.upgradeFrom(type, type.containedTypeOrUnknown(0));
    }
    return type;
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:28,
代码来源:VavrTypeModifier.java

示例19: expectedJson

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public static String expectedJson(Object o, int opts) {
    if (o instanceof Either) {
        return expectedEitherJson((Either<?, ?>) o, opts);
    }
    if (o instanceof Lazy) {
        return expectedLazyJson((Lazy<?>) o, opts);
    }
    if (o instanceof Option) {
        return expectedOptionJson((Option<?>) o, opts);
    }
    if (o instanceof PriorityQueue) {
        return expectedPriorityQueueJson((PriorityQueue<?>) o, opts);
    }
    if (o instanceof Seq) {
        return expectedSeqJson((Seq<?>) o, opts);
    }
    if (o instanceof Set) {
        return expectedSetJson((Set<?>) o, opts);
    }
    if (o instanceof Map) {
        return expectedMapJson((Map<?, ?>) o, opts);
    }
    if (o instanceof Multimap) {
        return expectedMultimapJson((Multimap<?, ?>) o, opts);
    }
    if (o instanceof Tuple) {
        return expectedTupleJson((Tuple) o, opts);
    }
    if (o instanceof String) {
        return "\"" + o.toString().replace("\"", "\\\"") + "\"";
    }
    return o.toString();
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:34,
代码来源:Serializer.java

示例20: test1

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void test1() throws IOException {
    Lazy<?> src = Lazy.of(() -> 1);
    String json = mapper().writer().writeValueAsString(src);
    Assert.assertEquals("1", json);
    Lazy<?> restored = mapper().readValue(json, Lazy.class);
    Assert.assertEquals(src, restored);
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:9,
代码来源:LazyTest.java

示例21: test2

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void test2() throws IOException {
    Lazy<?> src = Lazy.of(() -> null);
    String json = mapper().writer().writeValueAsString(src);
    Assert.assertEquals("null", json);
    Lazy<?> restored = mapper().readValue(json, Lazy.class);
    Assert.assertEquals(src, restored);
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:9,
代码来源:LazyTest.java

示例22: testAutoDiscovery

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
/**
 * Since there is no way (without reflection) to interrogate the mapper to see which modules
 * are loaded, we can do so indirectly by simply asking it to handle any vavr type.
 * Non-failure means success
 * @throws Exception only if jackson fails to handle vavr types - meaning auto-register didn't work
 */
@Test
public void testAutoDiscovery() throws Exception {
  ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();

  Lazy<?> src = Lazy.of(() -> 1);
  String json = mapper.writer().writeValueAsString(src);
  Assert.assertEquals("1", json);
  Lazy<?> restored = mapper.readValue(json, Lazy.class);
  Assert.assertEquals(src, restored);
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:17,
代码来源:ServiceLoaderTest.java

示例23: testValue

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testValue() throws IOException {
    V v = new V()
            .setLazy(Lazy.of(() -> new X("b", 2)))
            .setOption(Option.of(new X("c", 3)));
    json_roundtrip_test(v, V.class);
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:8,
代码来源:AbstractContentTest.java

示例24: testLazy

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Test
public void testLazy() throws Exception {
    Lazy<A> src = Lazy.of(() -> new B("a", "b"));
    String json = MAPPER.writeValueAsString(new LazyPojo().setValue(src));
    Assert.assertEquals(json, "{\"value\":{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}}");
    LazyPojo pojo = MAPPER.readValue(json, LazyPojo.class);
    Lazy<A> restored = pojo.getValue();
    Assert.assertTrue(restored.get() instanceof B);
    Assert.assertEquals(restored.get().a, "a");
    Assert.assertEquals(((B) restored.get()).b, "b");
}
 

开发者ID:vavr-io,
项目名称:vavr-jackson,
代码行数:12,
代码来源:ExtFieldsPojoTest.java

示例25: lazyResult

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("/lazy")
public Lazy<String> lazyResult() {
    return Lazy.of(() -> "lazy");
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:VavrApplication.java

示例26: lazyPathParam

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("/lazy-path/{param}")
public String lazyPathParam(@PathParam("param") Lazy<String> lazy) {
    return lazy.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:VavrApplication.java

示例27: lazyQueryParam

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("/lazy-query")
public String lazyQueryParam(@QueryParam("param") Lazy<String> lazy) {
    return lazy.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:VavrApplication.java

示例28: lazyHeaderParam

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("/lazy-header")
public String lazyHeaderParam(@HeaderParam("X-Lazy") Lazy<String> lazy) {
    return lazy.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:VavrApplication.java

示例29: lazyCookieParam

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("/lazy-cookie")
public String lazyCookieParam(@CookieParam("param") Lazy<String> lazy) {
    return lazy.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:VavrApplication.java

示例30: header

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("header")
public String header(@HeaderParam("param") Lazy<String> param) {
    return param.get();
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:LazyParamConverterProviderTest.java

示例31: cookie

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("cookie")
public String cookie(@CookieParam("param") Lazy<String> param) {
    return param.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:LazyParamConverterProviderTest.java

示例32: path

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("path/{param}")
public String path(@PathParam("param") Lazy<String> param) {
    return param.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:LazyParamConverterProviderTest.java

示例33: query

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("query")
public String query(@QueryParam("param") Lazy<String> param) {
    return param.getOrElseThrow(NotFoundException::new);
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:LazyParamConverterProviderTest.java

示例34: lazy

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("lazy")
public Lazy<String> lazy() {
    return Lazy.of(() -> "Foobar");
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:ValueMessageBodyWriterTest.java

示例35: lazyNull

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@GET
@Path("lazy-null")
public Lazy<String> lazyNull() {
    return null;
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:ValueMessageBodyWriterTest.java

示例36: responseLazy

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Path("response-lazy")
@GET
public Response responseLazy() {
    return Response.ok(Lazy.of(() -> "Foobar")).build();
}
 

开发者ID:dropwizard,
项目名称:dropwizard-vavr,
代码行数:6,
代码来源:ValueMessageBodyWriterTest.java

示例37: serialize

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
@Override
public JsonElement serialize(Lazy<?> src, Type type, JsonSerializationContext ctx) {
    return ctx.serialize(src.get());
}
 

开发者ID:vavr-io,
项目名称:vavr-gson,
代码行数:5,
代码来源:LazyConverter.java

示例38: widenK

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public static <T> Higher<lazy,T> widenK(final Lazy<T> completableList) {

        return new LazyKind<>(
                completableList);
    }
 

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

示例39: mapM

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public <W2,R> Nested<lazy,W2,R> mapM(Function<? super T,? extends Higher<W2,R>> fn, InstanceDefinitions<W2> defs){
    Lazy<Higher<W2, R>> e = map(fn);
    LazyKind<Higher<W2, R>> lk = LazyKind.widen(e);
    return Nested.of(lk, Lazys.Instances.definitions(), defs);
}
 

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

示例40: fold

点赞 2

import io.vavr.Lazy; //导入依赖的package包/类
public <R> LazyKind<R> fold(Function<? super Lazy<? super T>,? extends Lazy<R>> op){
    return widen(op.apply(boxed));
}
 

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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)