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

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

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

ReactiveSeq.mergeMap介绍

暂无

代码示例

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

@Override
public <R> IO<R> flatMap(Function<? super T, IO<? extends R>> s) {
  return new SyncIO<R>(fn.mergeMap(s));
}
@Override

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

@Override
public <R> IO<R> mergeMap(int maxConcurrency, Function<? super T, Publisher<? extends R>> s) {
  return new SyncIO<R>(fn.mergeMap(maxConcurrency,s));
}
@Override

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

/**
 * A potentially asynchronous flatMap operation where data from each publisher may arrive out of order
 *
 * @param mapper
 * @return
 */
public <R> ReactiveSeq<R> mergeMap(final int maxConcurrency, final Function<? super T, ? extends Publisher<? extends R>> mapper) {
  return Spouts.fromIterable(this).mergeMap(maxConcurrency,mapper);
}

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

@Override
public <R> IO<R> mergeMap(int maxConcurrency, Function<? super T, Publisher<? extends R>> s) {
  return fromPublisher(Spouts.from(fn).mergeMap(maxConcurrency,t -> s.apply(t)));
}

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

@Override
public <R> IO<R> flatMap(Function<? super T, IO<? extends R>> s) {
  return fromPublisher(Spouts.from(fn).mergeMap(t -> s.apply(t).publisher()));
}
@Override

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

@Test
public void flatMapP3(){
  System.out.println(this.of(1,2)
      .mergeMap(i->of(i,i*2,i*4)
          .mergeMap(x->of(5,6,7)
              .mergeMap(y->of(2,3,4))))
      .toList());
}
@Test

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

@Test
public void flatMapP(){
  assertThat(Spouts.of(1,2,3)
      .mergeMap(i->Spouts.of(i))
      .toList(),equalTo(Arrays.asList(1,2,3)));
}
@Test

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

@Test
public void nestedSync(){
  System.out.println(of(1, 2, 3)
      .mergeMap(2, i -> Spouts.of(5,6).mergeMap(2, k->Spouts.of(8,9))).toList());
}
@Test

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

@Test
public void mergeMapToList(){
  assertThat(of(1)
      .mergeMap(a->ReactiveSeq.of(1))
      .toList(),
    equalTo(Arrays.asList(1)));
}
@Test

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

@Test
public void flatMapPublisher() throws InterruptedException{
  //of(1,2,3)
  //		.flatMapP(i->Maybe.of(i)).printOut();
  assertThat(of(1,2,3)
          .mergeMap(i->Maybe.of(i))
          .toList(),equalTo(Arrays.asList(1,2,3)));
}

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

@Test
public void flatMapPublisher() throws InterruptedException{
 Assert.assertThat(of(1,2,3)
  .mergeMap(i-> Maybe.of(i))
  .toList().size(), Matchers.equalTo(3));
 Assert.assertThat(of(1,2,3)
  .mergeMap(i-> Maybe.of(i))
  .toList(), Matchers.containsInAnyOrder(3,2,1));
}

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

@Test
public void onEmptySwitchGet(){
  for(int i=0;i<ITERATIONS;i++){
  //for(int i=0;i<100_000;i++){
    System.out.println("Iteration " + i);
    assertThat(of()
            .onEmptyGet(() -> 1).mergeMap(a->ReactiveSeq.of(1))
            .toList(),
        equalTo(Arrays.asList(1)));
  }
}
@Test

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

@Test
public void range(){
    List<Integer> res =  Spouts.range(1,500)
                  .mergeMap(i -> nextAsync())
                  .toList();
    System.out.println("Result is " + res);
}

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

@Test
public void flatMapPublisher() throws InterruptedException{
  //of(1,2,3)
  //		.flatMapP(i->Maybe.of(i)).printOut();
  assertThat(of(1,2,3)
          .mergeMap(i->Maybe.of(i))
          .toList(),equalTo(Arrays.asList(1,2,3)));
}

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

@Test
public void flatMapPubIteration(){
  Iterator<Integer> it = of(1,2,3,4)
      .mergeMap(i->of(5,6)
          .mergeMap(k->of(k)))
      .iterator();
  assertThat(ReactiveSeq.fromIterator(it).size(),equalTo(8));
}
@Test

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

@Test
public void flatMapP2(){
  MatcherAssert.assertThat(Spouts.of(1,2,3)
      .mergeMap(i->Spouts.of(1,i))
      .toList(),Matchers.hasItems(1,1,1,2,1,3));
}
@Test

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

@Test
public void flatMapP(){
  assertThat(of(1,2,3)
      .mergeMap(i->Spouts.of(i))
      .toList(),Matchers.hasItems(1,2,3));
}
@Test

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

@Test
public void flatMapP2(){
  assertThat(of(1,2,3)
      .mergeMap(i->Spouts.of(1,i))
      .toList(),Matchers.hasItems(1,1,1,2,1,3));
}
@Test

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

@Test
public void flatMapPublisher() throws InterruptedException{
  //of(1,2,3)
  //		.flatMapP(i->Maybe.of(i)).printOut();
  assertThat(of(1,2,3)
          .mergeMap(i->Maybe.of(i))
          .toList(),Matchers.hasItems(1,2,3));
}

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

@Test
public void flatMapPublisher() throws InterruptedException{
  //of(1,2,3)
  //		.flatMapP(i->Maybe.of(i)).printOut();
  assertThat(of(1,2,3)
          .mergeMap(i->Maybe.of(i))
          .toList(),Matchers.hasItems(1,2,3));
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法