cyclops.reactive.ReactiveSeq.fromIterable()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中cyclops.reactive.ReactiveSeq.fromIterable方法的一些代码示例,展示了ReactiveSeq.fromIterable的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ReactiveSeq.fromIterable方法的具体详情如下:
包路径:cyclops.reactive.ReactiveSeq
类名称:ReactiveSeq
方法名:fromIterable

ReactiveSeq.fromIterable介绍

[英]Construct a ReactiveSeq from an Iterable
[中]从一个可测的构造一个反应序列

代码示例

代码示例来源:origin: aol/micro-server

private ListX<Plugin> load(){
     return  ReactiveSeq.fromIterable(ServiceLoader.load(Plugin.class)).to(ListX::fromIterable);
  }
}

代码示例来源:origin: aol/micro-server

@Override
public Class[] classes(Config config, Class... classes) {
  List<Class> classList = new ArrayList<Class>();
  classList.addAll(Arrays.asList(classes));
  return ReactiveSeq.fromIterable(new JerseyApplication(classList).classes).appendAll(classList)
          .toArray(i->new Class[i]);
}

代码示例来源:origin: aol/micro-server

public static Optional<RegisterEntry> toRegisterEntry(UriInfo uriInfo) {
  if (uriInfo.getQueryParameters().isEmpty()) {
    return Optional.empty();
  } else {
    MultivaluedMap<String, String> parameters = uriInfo.getQueryParameters();
    RegisterEntry re = RegisterEntry.builder()
      .context(parameters.getFirst("context"))
      .hostname(parameters.getFirst("hostname"))
      .port(toInt(parameters.getFirst("port")))
      .target(parameters.getFirst("target"))
      .externalPort(toInt(parameters.getFirst("externalPort")))
      .module(parameters.getFirst("module"))
      .health(toHealth(parameters.getFirst("health")))
      .build();
    Map<String, String> manifest = ReactiveSeq.fromIterable(parameters.entrySet())
      .filter(e -> e.getKey().startsWith("manifest."))
      .toMap(e -> e.getKey().replace("manifest.", ""),
        e -> parameters.getFirst(e.getKey()));
    re.getManifest().clear();
    re.getManifest().putAll(manifest);
    return Optional.of(re);
  }
}

代码示例来源:origin: aol/cyclops

/**
 * @return This Traversable converted to a Stream
 */
default ReactiveSeq<T> stream() {
  return ReactiveSeq.fromIterable(this);
}

代码示例来源:origin: aol/micro-server

@GET
@Path("/expensive")
@Produces("text/plain")
public void expensive(@Suspended AsyncResponse asyncResponse){
  FutureStream.builder().fromIterable(urls)
      .then(it->client.get(it))
      .onFail(it -> "")
      .peek(it -> 
      System.out.println(it))
      .convertToSimpleReact()
      .allOf(data -> {
        System.out.println(data);
          return asyncResponse.resume(ReactiveSeq.fromIterable(data).join(";")); });
}

代码示例来源:origin: aol/cyclops

default <R1, R> ImmutableQueue<R> forEach2(Function<? super T, ? extends Iterable<R1>> iterable1,
                      BiFunction<? super T, ? super R1, ? extends R> yieldingFunction) {
  return this.concatMap(in-> {
    Iterable<? extends R1> b = iterable1.apply(in);
    return ReactiveSeq.fromIterable(b)
        .map(in2->yieldingFunction.apply(in, in2));
  });
}

代码示例来源:origin: aol/cyclops

default <R1, R2, R> ImmutableQueue<R> forEach3(Function<? super T, ? extends Iterable<R1>> iterable1,
                        BiFunction<? super T, ? super R1, ? extends Iterable<R2>> iterable2,
                        Function3<? super T, ? super R1, ? super R2, ? extends R> yieldingFunction) {
  return this.concatMap(in -> {
    Iterable<R1> a = iterable1.apply(in);
    return ReactiveSeq.fromIterable(a)
        .flatMap(ina -> {
          ReactiveSeq<R2> b = ReactiveSeq.fromIterable(iterable2.apply(in, ina));
          return b.map(in2 -> yieldingFunction.apply(in, ina, in2));
        });
  });
}

代码示例来源:origin: aol/cyclops

@SafeVarargs
public static <T1> Predicate<Iterable<? super T1>> startsWith(final T1... items) {
  return test -> ReactiveSeq.fromIterable(test)
               .startsWith(ReactiveSeq.of(items));
}

代码示例来源:origin: aol/cyclops

@Override
public <U> ReactiveSeq<Tuple2<T, U>> crossJoin(ReactiveSeq<? extends U> other) {
  Streamable<? extends U> s = Streamable.fromStream(other);
  return forEach2(a->ReactiveSeq.fromIterable(s), Tuple::tuple);
}

代码示例来源:origin: aol/cyclops

public static <T,R1, R2, R> IterableX<R> forEach3( Iterable<T> host,final Function<? super T, ? extends Iterable<R1>> iterable1,
                          final BiFunction<? super T,? super R1, ? extends Iterable<R2>> iterable2,
                          final Function3<? super T, ? super R1, ? super R2, ? extends R> yieldingFunction) {
  return fromIterable(host).concatMap(in -> {
    Iterable<R1> a = iterable1.apply(in);
    return ReactiveSeq.fromIterable(a)
        .flatMap(ina -> {
          ReactiveSeq<R2> b = ReactiveSeq.fromIterable(iterable2.apply(in, ina));
          return b.map(in2 -> yieldingFunction.apply(in, ina, in2));
        });
  });
}

代码示例来源:origin: aol/cyclops

default Seq<T> take(final long num) {
  if( num <= 0)
    return Nil.Instance;
  return fromStream(ReactiveSeq.fromIterable(this).take(num));
}
default Seq<T> drop(final long num) {

代码示例来源:origin: aol/cyclops

default LazySeq<T> take(final long n) {
  if( n <= 0)
    return LazySeq.Nil.Instance;
  return fromStream(ReactiveSeq.fromIterable(this).take(n));
}
default LazySeq<T> takeWhile(Predicate<? super T> p) {

代码示例来源:origin: aol/cyclops

@Override
default BankersQueue<T> prependAll(Iterable<? extends T> value){
    Iterator<? extends T> it = ReactiveSeq.fromIterable(value).reverse().iterator();
    BankersQueue<T> res= this;
    while(it.hasNext()){
      res = res.prepend(it.next());
    }
    return res;
}

代码示例来源:origin: aol/cyclops

default Option<T> mode(){
  Map<T,Integer> map = stream().collect(Collectors.toMap(k->k, v->1,(a, b)->a+b));
  return ReactiveSeq.fromIterable(map.entrySet())
      .maxBy(k -> k.getValue())
      .map(t -> t.getKey());
}
default ReactiveSeq<Tuple2<T,Integer>> occurances(){

代码示例来源:origin: aol/cyclops

default <K1,K2,R1, R> ImmutableMap<K2,R> forEach2(Function<? super Tuple2<K, V>, ? extends Iterable<Tuple2<K1, R1>>> iterable1,
                         BiFunction<? super Tuple2<K, V>, ? super Tuple2<K1, R1>, ? extends Tuple2<K2, R>> yieldingFunction) {
  return this.concatMap((a1,b1) -> {
    Tuple2<K, V> in = Tuple.tuple(a1, b1);
    Iterable<Tuple2<K1,R1>> b = iterable1.apply(in);
    return ReactiveSeq.fromIterable(b)
        .map(in2->yieldingFunction.apply(in, in2));
  });
}

代码示例来源:origin: aol/cyclops

@Test
public void cycleIterateIterable(){
  Iterator<Integer> it = ReactiveSeq.fromIterable(Arrays.asList(1)).stream().cycle(2).iterator();
  List<Integer> list2 = new ArrayList<>();
  while(it.hasNext())
    list2.add(it.next());
  assertThat(list2,equalTo(Arrays.asList(1,1)));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void cycleIterateIterable(){
  Iterator<Integer> it = ReactiveSeq.fromIterable(Arrays.asList(1)).stream().cycle(2).iterator();
  List<Integer> list2 = new ArrayList<>();
  while(it.hasNext())
    list2.add(it.next());
  assertThat(list2,equalTo(Arrays.asList(1,1)));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void cycleIterateIterable(){
  Iterator<Integer> it = ReactiveSeq.fromIterable(Arrays.asList(1)).stream().cycle(2).iterator();
  List<Integer> list2 = new ArrayList<>();
  while(it.hasNext())
    list2.add(it.next());
  assertThat(list2,equalTo(Arrays.asList(1,1)));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void testDistinctReactiveSeqMultipleDuplicates(){
  List<String> names = Arrays.asList("Java", "C", "Java", "Java","java", "java");
  List<String> d = ReactiveSeq.fromIterable(names).distinct(n -> n + ":" + n).toList();
  System.out.println(d);
  assertThat(d.size(),is(3));
}

代码示例来源:origin: aol/cyclops

@Test
public void coflatMapTest(){
  ReactiveSeq<ReactiveSeq<Integer>> stream = ReactiveSeq.fromIterable(Arrays.asList(1,2,3))
                              .coflatMap(s -> s);
  ReactiveSeq<Integer> stream2 = stream.flatMap(s -> s).map(i -> i * 10);
  ReactiveSeq<Integer> stream3 = stream.flatMap(s -> s).map(i -> i * 100);
  assertThat(stream2.toList(),equalTo(Arrays.asList(10,20,30)));
  assertThat(stream3.toList(),equalTo(Arrays.asList(100,200,300)));
}
@Test

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法